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

Compiler allows to compile unsound code #1364

Closed
scabug opened this issue Sep 21, 2008 · 4 comments
Closed

Compiler allows to compile unsound code #1364

scabug opened this issue Sep 21, 2008 · 4 comments
Assignees

Comments

@scabug
Copy link

scabug commented Sep 21, 2008

Source code:

trait A {
  type T <: { type S[-U] }
  val x : T
  def y : x.S[AnyRef]
  def z : x.S[String] = y
}

object B extends A {
 type T = { type S[U] = U }
 val x : T = null
 def y : x.S[AnyRef] = new AnyRef
 def t : String = z
}

println(B.t)

Compiler version: 2.7.2.RC2

Actual result: Code compiles successfully, but throws an exception at run-time:

java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.String
	at Main$$$$anon$$1$$B$$.t((virtual file):16)
	at Main$$$$anon$$1.<init>((virtual file):19)
	at Main$$.main((virtual file):4)
	at Main.main((virtual file))
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	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.ScriptRunner$$.scala$$tools$$nsc$$ScriptRunner$$$$runCompiled(ScriptRunner.scala:382)
	at scala.tools.nsc.ScriptRunner$$$$anonfun$$runScript$$1.apply(ScriptRunner.scala:410)
	at scala.tools.nsc.ScriptRunner$$$$anonfun$$runScript$$1.apply(ScriptRunner.scala:409)
	at scala.tools.nsc.ScriptRunner$$.withCompiledScript(ScriptRunner.scala:354)
	at scala.tools.nsc.ScriptRunner$$.runScript(ScriptRunner.scala:409)
	at scala.tools.nsc.MainGenericRunner$$.main(MainGenericRunner.scala:179)
	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

Expected result: Compiler should not allow to drop variance annotations (in this case, on the type parameter U) when checking conformance of structural types.

@scabug
Copy link
Author

scabug commented Sep 21, 2008

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

@scabug
Copy link
Author

scabug commented Sep 30, 2008

@lrytz said:
related to #1363

@scabug
Copy link
Author

scabug commented Feb 24, 2011

@soc said:
The example doesn't compile anymore in 2.9 trunk:

<console>:18: error: overriding type T in trait A with bounds >: Nothing <: AnyRef{type S[-U]};
 type T has incompatible type
        type T = { type S[U] = U }
             ^

Maybe this was fixed?

@scabug
Copy link
Author

scabug commented Mar 3, 2011

@paulp said:
(In r24372) Test case closes #1364, no review.

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

No branches or pull requests

2 participants