Skip to content

Commit 450a6a8

Browse files
author
Aggelos Biboudis
authored
Merge pull request #4487 from dotty-staging/fix-classcastexception
Fix ClassCastException upon `class Foo extends Int => <someTerm>`
2 parents a5cca66 + 2732c6b commit 450a6a8

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,11 @@ class Typer extends Namer
15931593
val seenParents = mutable.Set[Symbol]()
15941594

15951595
def typedParent(tree: untpd.Tree): Tree = {
1596-
var result = if (tree.isType) typedType(tree)(superCtx) else typedExpr(tree)(superCtx)
1596+
def isTreeType(t: untpd.Tree): Boolean = t match {
1597+
case _: untpd.Apply => false
1598+
case _ => true
1599+
}
1600+
var result = if (isTreeType(tree)) typedType(tree)(superCtx) else typedExpr(tree)(superCtx)
15971601
val psym = result.tpe.dealias.typeSymbol
15981602
if (seenParents.contains(psym) && !cls.isRefinementClass) {
15991603
if (!ctx.isAfterTyper) ctx.error(i"$psym is extended twice", tree.sourcePos)

tests/neg/parser-stability-25.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class A extends (Int => i1) // error
2+
class B extends (Int => this) // error
3+
trait C {
4+
val bar: Int => this // error
5+
}
6+
7+
// Test that function types ending in SIP-23 singleton types are understood correctly.
8+
9+
class D extends (Int => 1) {
10+
def apply(x: Int) = 2 // error
11+
}
12+
13+
class Wrap(x: Int)
14+
class E extends (Wrap)( // error
15+
// error

tests/neg/parser-stability-26.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Test that function types ending in SIP-23 singleton types are understood correctly.
2+
class E extends (Int => 1) // error

tests/neg/parser-stability-27.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class F extends (Int => 1)( // error
2+
// error

tests/pos/singleton-fun-types.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
trait C extends (Int => 1)
2+
class D extends (Int => 1) {
3+
def apply(x: Int) = 1
4+
}

0 commit comments

Comments
 (0)