Skip to content

Add incompat: Inferred return type of an override method #189

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 1 commit into from
Apr 16, 2021

Conversation

adpi2
Copy link
Member

@adpi2 adpi2 commented Apr 16, 2021

Fixes #181

class Foo

class RichFoo(foo: Foo) extends Foo {
  def show: String = ""
}

class Parent {
  def foo: Foo = new Foo
}

class Child extends Parent {
  override def foo = new RichFoo(super.foo)
}

object Test {
  (new Child).foo.show // Scala 3 error: value show is not a member of Foo
}

@smarter Is the Scala 3 behavior intentional?

@adpi2 adpi2 force-pushed the add-infer-return-type branch from 85d3a30 to b1e5f39 Compare April 16, 2021 09:43
@smarter
Copy link

smarter commented Apr 16, 2021

Yes this is intended, the base methods determine the public API, if you want a different API you need to write the type down.

@adpi2 adpi2 merged commit 1d6aa99 into scalacenter:main Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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