@@ -775,7 +775,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
775
775
// todo: make sure dependent method types do not depend on implicits or by-name params
776
776
}
777
777
778
- def typedTypeDef (tdef : untpd.TypeDef , sym : Symbol )(implicit ctx : Context ): TypeDef = track(" typedTypeDef" ) {
778
+ def typedTypeDef (tdef : untpd.TypeDef , sym : Symbol )(implicit ctx : Context ): Tree = track(" typedTypeDef" ) {
779
779
val TypeDef (mods, name, rhs) = tdef
780
780
val mods1 = typedModifiers(mods)
781
781
val _ = typedType(rhs) // unused, typecheck only to remove from typedTree
@@ -858,47 +858,53 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
858
858
def typedAsFunction (tree : untpd.Tree , pt : Type )(implicit ctx : Context ): Tree =
859
859
typed(tree, if (defn.isFunctionType(pt)) pt else AnyFunctionProto )
860
860
861
- def typedNamed (xtree : untpd.NameTree , pt : Type )(implicit ctx : Context ): Tree = {
862
- val tree = xtree withName xtree.name.encode
863
- val sym = xtree.removeAttachment(SymOfTree ) match {
864
- case Some (sym) =>
865
- sym.ensureCompleted()
866
- sym
867
- case none =>
868
- NoSymbol
869
- }
870
-
871
- def localContext = {
872
- val freshCtx = ctx.fresh.setTree(xtree)
873
- if (sym.exists) freshCtx.setOwner(sym)
874
- else freshCtx // can happen for self defs
875
- }
861
+ /** Retrieve symbol attached to given tree */
862
+ protected def retrieveSym (tree : untpd.Tree )(implicit ctx : Context ) = tree.removeAttachment(SymOfTree ) match {
863
+ case Some (sym) =>
864
+ sym.ensureCompleted()
865
+ sym
866
+ case none =>
867
+ NoSymbol
868
+ }
876
869
877
- tree match {
878
- case tree : untpd.Ident => typedIdent(tree, pt)
879
- case tree : untpd.Select => typedSelect(tree, pt)
880
- case tree : untpd.SelectFromTypeTree => typedSelectFromTypeTree(tree, pt)
881
- case tree : untpd.Bind => typedBind(tree, pt)
882
- case tree : untpd.ValDef =>
883
- if (tree.isEmpty) tpd.EmptyValDef
884
- else typedValDef(tree, sym)(localContext.setNewScope)
885
- case tree : untpd.DefDef =>
886
- val typer1 = nestedTyper.remove(sym).get
887
- typer1.typedDefDef(tree, sym)(localContext.setTyper(typer1))
888
- case tree : untpd.TypeDef =>
889
- if (tree.isClassDef) typedClassDef(tree, sym.asClass)(localContext)
890
- else typedTypeDef(tree, sym)(localContext.setNewScope)
891
- case _ => typedUnadapted(desugar(tree), pt)
892
- }
870
+ /** A fresh local context with given tree and owner.
871
+ * Owner might not exist (can happen for self valdefs), in which case
872
+ * no owner is set in result context
873
+ */
874
+ protected def localContext (tree : untpd.Tree , owner : Symbol )(implicit ctx : Context ): FreshContext = {
875
+ val freshCtx = ctx.fresh.setTree(tree)
876
+ if (owner.exists) freshCtx.setOwner(owner) else freshCtx
893
877
}
894
878
879
+ protected def localTyper (sym : Symbol ): Typer = nestedTyper.remove(sym).get
880
+
895
881
def typedUnadapted (initTree : untpd.Tree , pt : Type = WildcardType )(implicit ctx : Context ): Tree = {
896
882
record(" typedUnadapted" )
897
883
val xtree = expanded(initTree)
898
884
xtree.removeAttachment(TypedAhead ) match {
899
885
case Some (ttree) => ttree
900
886
case none =>
901
887
888
+ def typedNamed (tree : untpd.NameTree , pt : Type )(implicit ctx : Context ): Tree = {
889
+ val sym = retrieveSym(xtree)
890
+ tree match {
891
+ case tree : untpd.Ident => typedIdent(tree, pt)
892
+ case tree : untpd.Select => typedSelect(tree, pt)
893
+ case tree : untpd.SelectFromTypeTree => typedSelectFromTypeTree(tree, pt)
894
+ case tree : untpd.Bind => typedBind(tree, pt)
895
+ case tree : untpd.ValDef =>
896
+ if (tree.isEmpty) tpd.EmptyValDef
897
+ else typedValDef(tree, sym)(localContext(tree, sym).setNewScope)
898
+ case tree : untpd.DefDef =>
899
+ val typer1 = localTyper(sym)
900
+ typer1.typedDefDef(tree, sym)(localContext(tree, sym).setTyper(typer1))
901
+ case tree : untpd.TypeDef =>
902
+ if (tree.isClassDef) typedClassDef(tree, sym.asClass)(localContext(tree, sym))
903
+ else typedTypeDef(tree, sym)(localContext(tree, sym).setNewScope)
904
+ case _ => typedUnadapted(desugar(tree), pt)
905
+ }
906
+ }
907
+
902
908
def typedUnnamed (tree : untpd.Tree ): Tree = tree match {
903
909
case tree : untpd.Apply =>
904
910
if (ctx.mode is Mode .Pattern ) typedUnApply(tree, pt) else typedApply(tree, pt)
@@ -938,8 +944,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
938
944
}
939
945
940
946
xtree match {
941
- case xtree : untpd.NameTree => typedNamed(xtree, pt)
942
- case xtree : untpd.Import => typedImport(xtree, xtree.removeAttachment( SymOfTree ).get )
947
+ case xtree : untpd.NameTree => typedNamed(xtree withName xtree.name.encode , pt)
948
+ case xtree : untpd.Import => typedImport(xtree, retrieveSym(xtree) )
943
949
case xtree => typedUnnamed(xtree)
944
950
}
945
951
}
0 commit comments