File tree Expand file tree Collapse file tree 4 files changed +65
-1
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 4 files changed +65
-1
lines changed Original file line number Diff line number Diff line change @@ -719,6 +719,22 @@ trait Checking {
719719 checkNoForwardDependencies(vparams1)
720720 case Nil =>
721721 }
722+
723+ /** Check that all named type that form part of this type have a denotation.
724+ * Called on inferred (result) types of ValDefs and DefDefs.
725+ * This could fail for types where the member was originally available as part
726+ * of the self type, yet is no longer visible once the `this` has been replaced
727+ * by some other prefix. See neg/i3083.scala
728+ */
729+ def checkMembersOK (tp : Type , pos : Position )(implicit ctx : Context ): Type = {
730+ val check : Type => Unit = {
731+ case ref : NamedType if ! ref.denot.exists =>
732+ ctx.error(em " $ref is not defined in inferred type $tp" , pos)
733+ case _ =>
734+ }
735+ tp.foreachPart(check, stopAtStatic = true )
736+ tp
737+ }
722738}
723739
724740trait NoChecking extends Checking {
@@ -738,4 +754,5 @@ trait NoChecking extends Checking {
738754 override def checkTraitInheritance (parentSym : Symbol , cls : ClassSymbol , pos : Position )(implicit ctx : Context ) = ()
739755 override def checkCaseInheritance (parentSym : Symbol , caseCls : ClassSymbol , pos : Position )(implicit ctx : Context ) = ()
740756 override def checkNoForwardDependencies (vparams : List [ValDef ])(implicit ctx : Context ): Unit = ()
757+ override def checkMembersOK (tp : Type , pos : Position )(implicit ctx : Context ): Type = tp
741758}
Original file line number Diff line number Diff line change @@ -1133,7 +1133,7 @@ class Namer { typer: Typer =>
11331133 case _ : untpd.DerivedTypeTree =>
11341134 WildcardType
11351135 case TypeTree () =>
1136- inferredType
1136+ checkMembersOK( inferredType, mdef.pos)
11371137 case DependentTypeTree (tpFun) =>
11381138 tpFun(paramss.head)
11391139 case TypedSplice (tpt : TypeTree ) if ! isFullyDefined(tpt.tpe, ForceDegree .none) =>
Original file line number Diff line number Diff line change 1+ object Main {
2+
3+ trait Literal {
4+ type F [T ]
5+ def num (i : Int ): F [Int ]
6+ }
7+
8+ trait Addition { self : Literal =>
9+ def add (l : F [Int ], r : F [Int ]): F [Int ]
10+ }
11+
12+ def expression (adder : Addition ) = {
13+ import adder ._
14+ add(num(1 ), num(2 )) // error // error (not found: num)
15+ }
16+ }
17+
18+ object Minimized {
19+ trait Literal {
20+ type F [T ]
21+ }
22+
23+ trait Addition { self : Literal =>
24+ def foo : F [Int ]
25+ }
26+
27+ object Main {
28+ def expression (adder : Addition ) = { // error: adder.F is not defined in inferred type
29+ adder.foo
30+ }
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ object Minimized {
2+ trait Literal {
3+ type F [T ]
4+ }
5+
6+ trait Addition { self : Literal =>
7+ def foo : F [Int ]
8+ }
9+
10+ object Main {
11+ def expression (adder : Addition & Literal ) = { // error: adder.F is not defined in inferred type
12+ adder.foo
13+ }
14+ }
15+ }
You can’t perform that action at this time.
0 commit comments