Skip to content

Fix #492. Traits that require an outer pointer are not SAMs. #496

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
Apr 23, 2015

Conversation

DarkDimius
Copy link
Contributor

No description provided.

def app[T, U](x: T)(f: F[T, U]): U = f(x)
app(1)(x => List(x))
def app1[T, U](x: T)(f: F1[T, U]): U = f(x)
def app2[T, U](x: T)(f: F2[T, U]): U = f(x)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be T.F2 instead of F2, or add import T._

@DarkDimius
Copy link
Contributor Author

@smarter please review. Does this unblock you?

@smarter
Copy link
Member

smarter commented Apr 23, 2015

It should yes, though I have a fix/workaround to avoid test failures on #411 I'll push soon.

@smarter
Copy link
Member

smarter commented Apr 23, 2015

LGTM but this does not prevent all the "fake" SAMs, as noted in #492 (comment)

trait X {
  def foo(): Int = 3
}

trait FakeSAM extends X {
  def apply(x: Int): Int
  override def foo(): Int = super.foo()
  // Get extra abstract method "private def super$foo(): Int"
}

And

trait FakeSAM2 {
  def apply(x: Int): Int
  val dummy: Int = 3
  // the val becomes:
  // <accessor> def dummy(): Int <--- extra abstract method
  // protected def initial$dummy(): Int = 3
}

I don't actually require this to be merged for #411 as I can easily avoid the test failure, so don't feel forced to merge it now.

@DarkDimius
Copy link
Contributor Author

I am aware of super-calls. But I do not want to make changes to handling of super-accessors before the refactoring is merged. I'll make it in a saparate PR later.

@DarkDimius
Copy link
Contributor Author

Second example is not a SAM - SAMs cannot have fields.

@smarter
Copy link
Member

smarter commented Apr 23, 2015

That's not a requirement of https://docs.oracle.com/javase/8/docs/api/java/lang/FunctionalInterface.html, static fields are allowed.

@DarkDimius
Copy link
Contributor Author

there's no such thing as static field in scala.
The only static thing that exists in scala is forwarders.

@odersky
Copy link
Contributor

odersky commented Apr 23, 2015

LGTM also

DarkDimius added a commit that referenced this pull request Apr 23, 2015
Fix #492. Traits that require an outer pointer are not SAMs.
@DarkDimius DarkDimius merged commit e47ecb1 into scala:master Apr 23, 2015
@allanrenucci allanrenucci deleted the fix-sams-static branch December 14, 2017 19:21
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.

3 participants