Skip to content

Fix ClassCastException upon class Foo extends Int => <someTerm> #4487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,11 @@ class Typer extends Namer
val seenParents = mutable.Set[Symbol]()

def typedParent(tree: untpd.Tree): Tree = {
var result = if (tree.isType) typedType(tree)(superCtx) else typedExpr(tree)(superCtx)
def isTreeType(t: untpd.Tree): Boolean = t match {
case _: untpd.Apply => false
case _ => true
}
var result = if (isTreeType(tree)) typedType(tree)(superCtx) else typedExpr(tree)(superCtx)
val psym = result.tpe.dealias.typeSymbol
if (seenParents.contains(psym) && !cls.isRefinementClass) {
if (!ctx.isAfterTyper) ctx.error(i"$psym is extended twice", tree.sourcePos)
Expand Down
15 changes: 15 additions & 0 deletions tests/neg/parser-stability-25.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class A extends (Int => i1) // error
class B extends (Int => this) // error
trait C {
val bar: Int => this // error
}

// Test that function types ending in SIP-23 singleton types are understood correctly.

class D extends (Int => 1) {
def apply(x: Int) = 2 // error
}

class Wrap(x: Int)
class E extends (Wrap)( // error
// error
2 changes: 2 additions & 0 deletions tests/neg/parser-stability-26.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Test that function types ending in SIP-23 singleton types are understood correctly.
class E extends (Int => 1) // error
2 changes: 2 additions & 0 deletions tests/neg/parser-stability-27.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class F extends (Int => 1)( // error
// error
4 changes: 4 additions & 0 deletions tests/pos/singleton-fun-types.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
trait C extends (Int => 1)
class D extends (Int => 1) {
def apply(x: Int) = 1
}