Skip to content

Commit 0fab13b

Browse files
committed
Harden checkMembersOK
We might provoke failures while checking whether all parts have a denotation. Also, if this is the case, we should not propagate the bad type.
1 parent f61596b commit 0fab13b

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,10 +1804,11 @@ object Types {
18041804
param.derivedSingleDenotation(param, argInfo)
18051805
}
18061806
else {
1807-
assert(ctx.reporter.errorsReported,
1808-
i"""bad parameter reference $this at ${ctx.phase}
1809-
|the parameter is ${param.showLocated} but the prefix $prefix
1810-
|does not define any corresponding arguments.""")
1807+
if (!ctx.reporter.errorsReported)
1808+
throw new TypeError(
1809+
i"""bad parameter reference $this at ${ctx.phase}
1810+
|the parameter is ${param.showLocated} but the prefix $prefix
1811+
|does not define any corresponding arguments.""")
18111812
NoDenotation
18121813
}
18131814
}

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import config.Printers.typr
3232
import NameKinds.DefaultGetterName
3333

3434
import collection.mutable
35-
import SymDenotations.NoCompleter
35+
import SymDenotations.{NoCompleter, NoDenotation}
3636
import dotty.tools.dotc.reporting.diagnostic.{ErrorMessageID, Message}
3737
import dotty.tools.dotc.reporting.diagnostic.messages._
3838
import dotty.tools.dotc.transform.ValueClasses._
@@ -731,20 +731,25 @@ trait Checking {
731731
case Nil =>
732732
}
733733

734-
/** Check that all named type that form part of this type have a denotation.
734+
/** Check that all named types that form part of this type have a denotation.
735735
* Called on inferred (result) types of ValDefs and DefDefs.
736736
* This could fail for types where the member was originally available as part
737737
* of the self type, yet is no longer visible once the `this` has been replaced
738738
* by some other prefix. See neg/i3083.scala
739739
*/
740740
def checkMembersOK(tp: Type, pos: Position)(implicit ctx: Context): Type = {
741+
var ok = true
741742
val check: Type => Unit = {
742-
case ref: NamedType if !ref.denot.exists =>
743-
ctx.error(em"$ref is not defined in inferred type $tp", pos)
743+
case ref: NamedType =>
744+
val d = try ref.denot catch { case ex: TypeError => NoDenotation }
745+
if (!d.exists) {
746+
ctx.error(em"$ref is not defined in inferred type $tp", pos)
747+
ok = false
748+
}
744749
case _ =>
745750
}
746751
tp.foreachPart(check, stopAtStatic = true)
747-
tp
752+
if (ok) tp else UnspecifiedErrorType
748753
}
749754

750755
/** Check that all non-synthetic references of the form `<ident>` or

tests/neg/parser-stability-7.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class x0[x1] {
2+
def x2: x1
3+
}
4+
trait x3 extends x0 {
5+
class x2
6+
var x2 = 0 // error
7+
var x4 = x5 x2 // error
8+
}

0 commit comments

Comments
 (0)