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

Unsoundness with refined SAM #5556

Closed
panacekcz opened this issue Dec 1, 2018 · 1 comment
Closed

Unsoundness with refined SAM #5556

panacekcz opened this issue Dec 1, 2018 · 1 comment

Comments

@panacekcz
Copy link
Contributor

When instantiating SAMs, type refinement is not checked, allowing contradicting types.

This compiles but fails at runtime:

trait SAM {
  type T >: Int
  def apply(x: Int): Int
  def t: T = 1
}

object O{
  def main(a:Array[String])={
    val fn: SAM {type T = String} = (i:Int) => i
    def cce: String = fn.t 
    println(cce)
  }
}

Output:

Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
	at O$.cce$1(SamUnsound.scala:10)
	at O$.main(SamUnsound.scala:11)
	at O.main(SamUnsound.scala)
@Blaisorblade
Copy link
Contributor

Thanks for the catch!

odersky added a commit that referenced this issue Dec 17, 2018
Fix #5556: Check SAM types for realizability
nicolasstucki pushed a commit to dotty-staging/dotty that referenced this issue Jan 5, 2019
Also: avoid shortcuts in findMember which can mask bad bounds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants