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

Structurals do not distinguish def and val - it is unsound #2079

Closed
scabug opened this issue Jun 19, 2009 · 4 comments
Closed

Structurals do not distinguish def and val - it is unsound #2079

scabug opened this issue Jun 19, 2009 · 4 comments
Assignees

Comments

@scabug
Copy link

scabug commented Jun 19, 2009

trait A {
  type T
  var v : T
}

object B {
  def f(x : { val y : A }) { x.y.v = x.y.v } 
  
  var a : A = _
  var b : Boolean = false
  def y : A = {
    if(b) {
      a = new A { type T = Int; var v = 1 }
      a
    } else {
      a = new A { type T = String; var v = "" }
      b = true
      a
    }
  }
}

Scala 2.8.0.r18050-b20090618020144 compiles this code without errors. But it is unsound:

scala> B.f(B)
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
        at B$$$$anon$$2.v_$$eq(<console>:15)
        at B$$.f(<console>:6)
        at .<init>(<console>:7)
        at .<clinit>(<console>)
        at RequestResult$$.<init>(<console>:4)
        at RequestResult$$.<clinit>(<console>)
        at RequestResult$$result(<console>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
@scabug
Copy link
Author

scabug commented Jun 19, 2009

Imported From: https://issues.scala-lang.org/browse/SI-2079?orig=1
Reporter: Vladimir Reshetnikov (nikov)

@scabug
Copy link
Author

scabug commented Jun 22, 2009

@phaller said:
Added test (in pending/neg/t2079.scala).

@scabug
Copy link
Author

scabug commented Jun 14, 2010

@dubochet said:
Upping crashers to hight priority.

@scabug
Copy link
Author

scabug commented Jul 5, 2010

@dubochet said:
Duplicate of #963.

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

2 participants