@@ -376,17 +376,6 @@ class Namer { typer: Typer =>
376
376
case tree : TypeDef =>
377
377
if (flags.is(Opaque ) && ctx.owner.isClass) ctx.owner.setFlag(Opaque )
378
378
new TypeDefCompleter (tree)(cctx)
379
- case tree : ValDef if ctx.explicitNulls && ctx.owner.is(Method ) && ! tree.mods.isOneOf(Lazy | Implicit ) =>
380
- // Use a completer that completes itself with the completion text, so
381
- // we can use flow typing for `ValDef`s.
382
- // Don't use this special kind of completer for `lazy` or `implicit` symbols,
383
- // because those could be completed through a forward reference:
384
- // e.g.
385
- // val x: String|Null = ???
386
- // y /* y is completed through a forward reference! */
387
- // if (x == null) throw new NullPointerException()
388
- // lazy val y: Int = x.length
389
- new ValDefInBlockCompleter (tree)(cctx)
390
379
case _ =>
391
380
new Completer (tree)(cctx)
392
381
}
@@ -767,23 +756,22 @@ class Namer { typer: Typer =>
767
756
768
757
protected def localContext (owner : Symbol ): FreshContext = ctx.fresh.setOwner(owner).setTree(original)
769
758
770
- /** The context in which the completer should be typed: usually it's the creation context,
771
- * but could also be the completion context.
772
- */
773
- protected def typingContext (owner : Symbol , completionCtx : Context ): FreshContext = localContext(owner)
774
-
775
759
/** The context with which this completer was created */
776
760
def creationContext : Context = ctx
777
761
ctx.typerState.markShared()
778
762
779
- protected def typeSig (sym : Symbol , completionCtx : Context ): Type = original match {
763
+ protected def typeSig (sym : Symbol , ctx : Context ): Type = original match {
780
764
case original : ValDef =>
781
765
if (sym.is(Module )) moduleValSig(sym)
782
- else valOrDefDefSig(original, sym, Nil , Nil , identity)(typingContext(sym, completionCtx).setNewScope)
766
+ else {
767
+ val withNewScope = ctx.fresh.setOwner(sym).setTree(original).setNewScope
768
+ valOrDefDefSig(original, sym, Nil , Nil , identity)(withNewScope)
769
+ }
783
770
case original : DefDef =>
784
771
val typer1 = ctx.typer.newLikeThis
785
772
nestedTyper(sym) = typer1
786
- typer1.defDefSig(original, sym)(localContext(sym).setTyper(typer1))
773
+ val withTyper = ctx.fresh.setOwner(sym).setTree(original).setTyper(typer1)
774
+ typer1.defDefSig(original, sym)(withTyper)
787
775
case imp : Import =>
788
776
try {
789
777
val expr1 = typedAheadExpr(imp.expr, AnySelectionProto )
@@ -810,7 +798,8 @@ class Namer { typer: Typer =>
810
798
denot.info = UnspecifiedErrorType
811
799
}
812
800
else {
813
- completeInContext(denot, ctx)
801
+ // the default behaviour is to complete using creation context
802
+ completeInContext(denot, this .ctx)
814
803
if (denot.isCompleted) registerIfChild(denot)
815
804
}
816
805
}
@@ -893,49 +882,24 @@ class Namer { typer: Typer =>
893
882
}
894
883
}
895
884
896
- /** Intentionally left without `implicit ctx` parameter. We need
897
- * to pick up the context at the point where the completer was created .
885
+ /** Intentionally left without `implicit ctx` parameter.
886
+ * We use the given ctx to complete this Completer .
898
887
*
899
- * If -Yexplicit-nulls, is enabled, we sometimes use the completion context.
900
- * See `ValDefInBlockCompleter`.
888
+ * Normally, the creation context is passed, as passed in the complete method.
889
+ * However, if -Yexplicit-nulls, is enabled, we pass in the current context
890
+ * so that flow typing works with blocks.
901
891
*/
902
- def completeInContext (denot : SymDenotation , completionContext : Context ): Unit = {
892
+ def completeInContext (denot : SymDenotation , ctx : Context ): Unit = {
903
893
val sym = denot.symbol
904
894
addAnnotations(sym)
905
895
addInlineInfo(sym)
906
- denot.info = typeSig(sym, completionContext )
896
+ denot.info = typeSig(sym, ctx )
907
897
invalidateIfClashingSynthetic(denot)
908
898
Checking .checkWellFormed(sym)
909
899
denot.info = avoidPrivateLeaks(sym)
910
900
}
911
901
}
912
902
913
- /** A completer that uses its completion context (as opposed to the creation context)
914
- * to complete itself. This is used so that flow typing can handle `ValDef`s that appear within a block.
915
- *
916
- * Example:
917
- * Suppose we have a block containing
918
- *
919
- * 1. val x: String|Null = ???
920
- * 2. if (x == null) throw NPE
921
- * 3. val y = x
922
- *
923
- * We want to infer y: String on line 3, but if the completer for `y` uses its creation context,
924
- * then we won't have the additional flow facts that say that `y` is not null.
925
- *
926
- * The solution is to use a completer that completes itself using the context at completion time,
927
- * as opposed to creation time. Normally, we need to use the creation context, because a completer
928
- * can be completed at any point in the future. However, for `ValDef`s within a block, we know they'll
929
- * be completed immediately after the symbols are created, so it's safe to use this new kind of completer.
930
- */
931
- class ValDefInBlockCompleter (original : ValDef )(implicit ctx : Context ) extends Completer (original)(ctx) {
932
- assert(ctx.explicitNulls)
933
-
934
- override def typingContext (owner : Symbol , completionCtx : Context ): FreshContext = {
935
- completionCtx.fresh.setOwner(owner).setTree(original)
936
- }
937
- }
938
-
939
903
class TypeDefCompleter (original : TypeDef )(ictx : Context ) extends Completer (original)(ictx) with TypeParamsCompleter {
940
904
private [this ] var myTypeParams : List [TypeSymbol ] = null
941
905
private [this ] var nestedCtx : Context = null
@@ -964,7 +928,7 @@ class Namer { typer: Typer =>
964
928
myTypeParams
965
929
}
966
930
967
- override protected def typeSig (sym : Symbol , completionContext : Context ): Type =
931
+ override protected def typeSig (sym : Symbol , ctx : Context ): Type =
968
932
typeDefSig(original, sym, completerTypeParams(sym)(ictx))(nestedCtx)
969
933
}
970
934
@@ -1134,7 +1098,7 @@ class Namer { typer: Typer =>
1134
1098
}
1135
1099
1136
1100
/** The type signature of a ClassDef with given symbol */
1137
- override def completeInContext (denot : SymDenotation , completionContext : Context ): Unit = {
1101
+ override def completeInContext (denot : SymDenotation , ctx : Context ): Unit = {
1138
1102
val parents = impl.parents
1139
1103
1140
1104
/* The type of a parent constructor. Types constructor arguments
@@ -1170,26 +1134,26 @@ class Namer { typer: Typer =>
1170
1134
* (4) If the class is sealed, it is defined in the same compilation unit as the current class
1171
1135
*/
1172
1136
def checkedParentType (parent : untpd.Tree ): Type = {
1173
- val ptype = parentType(parent)(ctx.superCallContext).dealiasKeepAnnots
1137
+ val ptype = parentType(parent)(this . ctx.superCallContext).dealiasKeepAnnots
1174
1138
if (cls.isRefinementClass) ptype
1175
1139
else {
1176
1140
val pt = checkClassType(ptype, parent.sourcePos,
1177
1141
traitReq = parent ne parents.head, stablePrefixReq = true )
1178
1142
if (pt.derivesFrom(cls)) {
1179
1143
val addendum = parent match {
1180
- case Select (qual : Super , _) if ctx.scala2Mode =>
1144
+ case Select (qual : Super , _) if this . ctx.scala2Mode =>
1181
1145
" \n (Note that inheriting a class of the same name is no longer allowed)"
1182
1146
case _ => " "
1183
1147
}
1184
- ctx.error(CyclicInheritance (cls, addendum), parent.sourcePos)
1148
+ this . ctx.error(CyclicInheritance (cls, addendum), parent.sourcePos)
1185
1149
defn.ObjectType
1186
1150
}
1187
1151
else {
1188
1152
val pclazz = pt.typeSymbol
1189
1153
if (pclazz.is(Final ))
1190
- ctx.error(ExtendFinalClass (cls, pclazz), cls.sourcePos)
1154
+ this . ctx.error(ExtendFinalClass (cls, pclazz), cls.sourcePos)
1191
1155
if (pclazz.is(Sealed ) && pclazz.associatedFile != cls.associatedFile)
1192
- ctx.error(UnableToExtendSealedClass (pclazz), cls.sourcePos)
1156
+ this . ctx.error(UnableToExtendSealedClass (pclazz), cls.sourcePos)
1193
1157
pt
1194
1158
}
1195
1159
}
0 commit comments