scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Bad inference of override with dependent result #12621

Open som-snytt opened 2 years ago

som-snytt commented 2 years ago

Reproduction steps

➜  ~ skala -Xsource:3
Welcome to Scala 2.13.9-20220720-072233-0771b75 (OpenJDK 64-Bit Server VM, Java 18.0.1.1).
Type in expressions for evaluation. Or try :help.

scala> class C { def f(sb: StringBuilder): sb.type = sb }
class C

scala> class D extends C { override def f(sb: StringBuilder) = sb }
                                        ^
       error: incompatible type in overriding
       def f(sb: StringBuilder): sb.type (defined in class C);
        found   : (sb: StringBuilder): StringBuilder
        required: (sb: StringBuilder): sb.type

Problem

Under -Xsource:3, infer the result type from the overridden method.

Welcome to Scala 3.1.3 (18.0.1.1, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> class C { def f(sb: StringBuilder): sb.type = sb }
// defined class C

scala> class D extends C { override def f(sb: StringBuilder) = sb }
// defined class D

scala>
SethTisue commented 1 year ago

scala/scala#10334 seems abandoned

som-snytt commented 1 year ago

I wanted to kick my stalled PRs out of the queue, but they might jump back on.

SethTisue commented 1 year ago

Yup. Just clearing out the 2.13.12 milestone and making a little noise in case either you or someone else wants to return to it.