File tree Expand file tree Collapse file tree 3 files changed +50
-1
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 3 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -722,6 +722,22 @@ trait Checking {
722
722
checkNoForwardDependencies(vparams1)
723
723
case Nil =>
724
724
}
725
+
726
+ /** Check that all named type that form part of this type have a denotation.
727
+ * Called on inferred (result) types of ValDefs and DefDefs.
728
+ * This could fail for types where the member was originally available as part
729
+ * of the self type, yet is no longer visible once the `this` has been replaced
730
+ * by some other prefix. See neg/i3083.scala
731
+ */
732
+ def checkMembersOK (tp : Type , pos : Position )(implicit ctx : Context ): Type = {
733
+ val check : Type => Unit = {
734
+ case ref : NamedType if ! ref.denot.exists =>
735
+ ctx.error(em " $ref is not defined in inferred type $tp" , pos)
736
+ case _ =>
737
+ }
738
+ tp.foreachPart(check, stopAtStatic = true )
739
+ tp
740
+ }
725
741
}
726
742
727
743
trait NoChecking extends Checking {
@@ -741,4 +757,5 @@ trait NoChecking extends Checking {
741
757
override def checkTraitInheritance (parentSym : Symbol , cls : ClassSymbol , pos : Position )(implicit ctx : Context ) = ()
742
758
override def checkCaseInheritance (parentSym : Symbol , caseCls : ClassSymbol , pos : Position )(implicit ctx : Context ) = ()
743
759
override def checkNoForwardDependencies (vparams : List [ValDef ])(implicit ctx : Context ): Unit = ()
760
+ override def checkMembersOK (tp : Type , pos : Position )(implicit ctx : Context ): Type = tp
744
761
}
Original file line number Diff line number Diff line change @@ -1098,7 +1098,7 @@ class Namer { typer: Typer =>
1098
1098
case _ : untpd.DerivedTypeTree =>
1099
1099
WildcardType
1100
1100
case TypeTree () =>
1101
- inferredType
1101
+ checkMembersOK( inferredType, mdef.pos)
1102
1102
case DependentTypeTree (tpFun) =>
1103
1103
tpFun(paramss.head)
1104
1104
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
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 (?)
29
+ adder.foo
30
+ }
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments