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 @@ -719,6 +719,22 @@ trait Checking {
719
719
checkNoForwardDependencies(vparams1)
720
720
case Nil =>
721
721
}
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
+ }
722
738
}
723
739
724
740
trait NoChecking extends Checking {
@@ -738,4 +754,5 @@ trait NoChecking extends Checking {
738
754
override def checkTraitInheritance (parentSym : Symbol , cls : ClassSymbol , pos : Position )(implicit ctx : Context ) = ()
739
755
override def checkCaseInheritance (parentSym : Symbol , caseCls : ClassSymbol , pos : Position )(implicit ctx : Context ) = ()
740
756
override def checkNoForwardDependencies (vparams : List [ValDef ])(implicit ctx : Context ): Unit = ()
757
+ override def checkMembersOK (tp : Type , pos : Position )(implicit ctx : Context ): Type = tp
741
758
}
Original file line number Diff line number Diff line change @@ -1103,7 +1103,7 @@ class Namer { typer: Typer =>
1103
1103
case _ : untpd.DerivedTypeTree =>
1104
1104
WildcardType
1105
1105
case TypeTree () =>
1106
- inferredType
1106
+ checkMembersOK( inferredType, mdef.pos)
1107
1107
case DependentTypeTree (tpFun) =>
1108
1108
tpFun(paramss.head)
1109
1109
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