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

Another type soundness hole #1557

Closed
scabug opened this issue Dec 2, 2008 · 5 comments
Closed

Another type soundness hole #1557

scabug opened this issue Dec 2, 2008 · 5 comments

Comments

@scabug
Copy link

scabug commented Dec 2, 2008

Essentially the same problem volatility was introduced to deal with, but in this case there are never any abstract types involved:

object Test extends Application {
 trait A
 trait B extends A

  trait C {
    trait D { type T >: B <: A }
    val y: (D with this.type)#T = new B { }
  }

  class D extends C {
    trait E
    type T = E 
    def frob(arg : E) : E = arg
    frob(y)
  }

  new D
}

Yielding:

java.lang.ExceptionInInitializerError
        at Test.main(volatile-intersection.scala)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at scala.tools.nsc.ObjectRunner$$$$anonfun$$run$$1.apply(ObjectRunner.scala:75)
	at scala.tools.nsc.ObjectRunner$$.withContextClassLoader(ObjectRunner.scala:49)
	at scala.tools.nsc.ObjectRunner$$.run(ObjectRunner.scala:74)
	at scala.tools.nsc.MainGenericRunner$$.main(MainGenericRunner.scala:154)
	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
Caused by: java.lang.ClassCastException: Test$$C$$$$anon$$1
	at Test$$D.<init>(volatile-intersection.scala:14)
	at Test$$.<init>(volatile-intersection.scala:17)
	at Test$$.<clinit>(volatile-intersection.scala)
	... 10 more
@scabug
Copy link
Author

scabug commented Dec 2, 2008

Imported From: https://issues.scala-lang.org/browse/SI-1557?orig=1
Reporter: Geoffrey Alan Washburn (washburn)
See #5517

@scabug
Copy link
Author

scabug commented Dec 2, 2008

Geoffrey Alan Washburn (washburn) said:
It is worth noting that is it not necessary to use "this.type" or an equivalent self-name:

object Test extends Application {
 trait A
 trait B extends A

  trait C {
    val x : AnyRef
    trait D { type T >: B <: A }
    val y: (D with x.type)#T = new B { }
  }

  class D extends C {
    trait E
    val x : AnyRef { type T = E} = null
    def frob(arg : E) : E = arg
    frob(y)
  }

  new D
}

@scabug
Copy link
Author

scabug commented Jul 18, 2011

@soc said:
Both throw a CCE instead now:

{{{code}}}
java.lang.ClassCastException: Test$C$$anon$1 cannot be cast to Test$D$E
at Test$D.(:21)
at Test$.(:24)
at Test$.()
at .(:9)
at .()
at .(:11)
at .()

{{{code}}}

@scabug
Copy link
Author

scabug commented May 6, 2012

@heathermiller said:
Still throws the above class cast exception.

This shouldn't compile. The type of y is able to be changed through x.

Test case added, test/pending/neg/t1557.scala. (pull request)

@scabug
Copy link
Author

scabug commented Mar 22, 2013

@paulp said:
Sorry you have not been fixed, #1557, but now I am consolidating you with some related soundness issues under #7278.

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