Skip to content

Scala 2 overrides a return type to an inferred type; Scala 3 does not #181

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

Closed
SethTisue opened this issue Apr 12, 2021 · 4 comments · Fixed by #189
Closed

Scala 2 overrides a return type to an inferred type; Scala 3 does not #181

SethTisue opened this issue Apr 12, 2021 · 4 comments · Fixed by #189

Comments

@SethTisue
Copy link
Contributor

scala 2.13.5> class C; class D extends C
scala 2.13.5> class Test { def foo: C = new C }
scala 2.13.5> class Test2 extends Test { override def foo = new D }
scala 2.13.5> (new Test2).foo
val res0: D = D@5d32c1c7

whereas in Scala 3 the type of res0 is C

I'm fairly sure this is intended behavior in Scala 3, but I can't seem to find either a ticket, or a migration guide entry about it.

There is a ticket complaining about the Scala 2 behavior: scala/bug#7212

@adpi2
Copy link
Member

adpi2 commented Apr 12, 2021

Thanks for reporting!

Do you think this pattern could cause a compiler error when porting a valid piece of Scala 2.13 code to Scala 3?

@SethTisue
Copy link
Contributor Author

Yes, it happened here: scala/scala-parser-combinators#370

@dwijnand
Copy link

scala/scala-parser-combinators#370 isn't a compiler error, it's a runtime error. And I still don't really think either compiler's at fault, as it's just some crazy class casting code

      def apply(in: Input) = {
        /*
         * transformed reader
         */
        val inMem = in.asInstanceOf[PackratReader[Elem]]

@SethTisue
Copy link
Contributor Author

isn't a compiler error, it's a runtime error

fair. in any case, it's a potential migration concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants