Skip to content

Commit 8b80c3d

Browse files
committed
On invalid prefix, throw a TypeError
Previously, the type was set to UnspecifiedErrorType. But that violates the rule that every ErrorType has to be reported. If that does not happen, crashes in pickler will result.
1 parent ceca748 commit 8b80c3d

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2751,7 +2751,8 @@ object Types {
27512751
NamedType(prefix, name, d)
27522752
}
27532753
if (prefix eq this.prefix) this
2754-
else if !NamedType.validPrefix(prefix) then UnspecifiedErrorType
2754+
else if !NamedType.validPrefix(prefix) then
2755+
throw TypeError(em"invalid new prefix $prefix cannot replace ${this.prefix} in type $this")
27552756
else if (lastDenotation == null) NamedType(prefix, designator)
27562757
else designator match {
27572758
case sym: Symbol =>
@@ -5400,6 +5401,9 @@ object Types {
54005401
def explanation(using Context): String = msg.message
54015402
}
54025403

5404+
/** Note: Make sure an errors is reported before construtcing this
5405+
* as the type of a tree.
5406+
*/
54035407
object ErrorType:
54045408
def apply(m: Message)(using Context): ErrorType =
54055409
val et = new PreviousErrorType

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,9 @@ class TreePickler(pickler: TastyPickler) {
699699
case ex: AssertionError =>
700700
println(i"error when pickling tree $tree")
701701
throw ex
702+
case ex: MatchError =>
703+
println(i"error when pickling tree $tree")
704+
throw ex
702705
}
703706
}
704707

tests/neg/i18058.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
trait F:
2+
type A
3+
4+
type G = (f: _ <: F) => f.A // error

0 commit comments

Comments
 (0)