Skip to content
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

AssertionError on anonymous class with refinement type and missing type parameters #11337

Closed
propensive opened this issue Mar 27, 2017 · 7 comments
Assignees
Labels
compiler crash fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)
Milestone

Comments

@propensive
Copy link

The following combination causes a compiler crash in typer with Scala 2.12.1:

trait Foo[T]
object Foo {
  val foo: Foo[Any] { type Bar = Any } = new Foo { def baz(): Any = () }
}

I think the correct behavior should be to just output the error regarding the missing parameters on new Foo, and give up. Full output is here: error.txt.

The crash also appears with 2.12.0, but not 2.11.8.

@SethTisue SethTisue transferred this issue from scala/scala-dev Jan 9, 2019
@SethTisue
Copy link
Member

someone want to check if this 1) should remain open and 2) isn't a duplicate?

@SethTisue SethTisue added this to the Backlog milestone Jan 9, 2019
@joroKr21
Copy link
Member

It's still a problem. There are 5 other issues about foundType is Erroneous:
#10803, #10015, #10003, #9960, #1472

@joroKr21
Copy link
Member

tree.tpe = <error>{}
tree.tpe.isErroneous = false

🤔

@SethTisue SethTisue added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Jan 10, 2019
@SethTisue
Copy link
Member

Dotty:

  |                                   found:    Object with Foo[Nothing]{...}
  |                                   required: Foo[Any]{Bar = Any}

@joroKr21
Copy link
Member

joroKr21 commented Jan 12, 2019

But dotty doesn't issue an error about trait Foo takes type parameters because it has type inference on extends (I think there's an issue about that but can't find it). The problem is that:

new Foo { def baz(): Any = () }

desugars to something like:

{
  class anon$1 extends Foo { // here dotty infers Nothing but scalac doesn't try to
    def baz(): Any = ()
  }
  new anon$1
}

Instead anon$1 ends up having an error type as a parent as in class anon$1 extends <error>. But TypeMap and by extension isErroneous don't look in the parents.

However AdaptTypeError exposes the parents:
https://github.com/scala/scala/blob/284a9c03c650c76e2b5295fee5c03565bcdf5246/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala#L212-L215

@joroKr21
Copy link
Member

I believe we should not try so hard to construct a meaningful type mismatch error for an anonymous class with erroneous definition.

@joroKr21
Copy link
Member

PR here scala/scala#7635

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler crash fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)
Projects
None yet
Development

No branches or pull requests

3 participants