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
Overly permissive overriding allowed in refinements: unsound #963
Comments
Imported From: https://issues.scala-lang.org/browse/SI-963?orig=1 |
@dragos said: |
@odersky said: |
@paulp said: // example mostly by DRMacIver, prettified a bit by paulp
object o {
trait X { type T; def t: T; def doStuff(t : T): Unit }
var stuff: X = new X {
type T = String
def t = "abc"
def doStuff(t: String) = ()
}
// here is the hole: x will now be treated as a stable identifier
// even though the actual implementation of it is a def, because
// structural types don't perform the necessary override checks
val evil: { val x: X } = new { def x = stuff }
// t is a String
val t = evil.x.t
// replace "stable" id with method which thinks t is an Int
stuff = new X {
type T = Int
def t = 21
def doStuff(t : Int) = ()
}
// oh noes!
def cce() = evil.x.doStuff(t)
} |
@paulp said: |
@soc said: import scala.util.Random
val r = new Random()
val y : { val x : java.lang.Integer } = new { def x = new java.lang.Integer(r.nextInt) }
val w1 : y.x.type = y.x //<--- scala.MatchError: None (of class scala.None$$)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.scala$$tools$$nsc$$backend$$icode$$GenICode$$ICodePhase$$$$genStat(GenICode.scala:169)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase$$$$anonfun$$genStat$$1.apply(GenICode.scala:143)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase$$$$anonfun$$genStat$$1.apply(GenICode.scala:143)
at scala.collection.LinearSeqOptimized$$class.foldLeft(LinearSeqOptimized.scala:111)
at scala.collection.immutable.List.foldLeft(List.scala:45)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.genStat(GenICode.scala:143)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.scala$$tools$$nsc$$backend$$icode$$GenICode$$ICodePhase$$$$genLoad(GenICode.scala:1052)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.gen(GenICode.scala:114)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase$$$$anonfun$$gen$$1.apply(GenICode.scala:69)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase$$$$anonfun$$gen$$1.apply(GenICode.scala:69)
at scala.collection.LinearSeqOptimized$$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.gen(GenICode.scala:69)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.gen(GenICode.scala:136)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.gen(GenICode.scala:88)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase$$$$anonfun$$gen$$1.apply(GenICode.scala:69)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase$$$$anonfun$$gen$$1.apply(GenICode.scala:69)
at scala.collection.LinearSeqOptimized$$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.gen(GenICode.scala:69)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.gen(GenICode.scala:79)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.gen(GenICode.scala:65)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.apply(GenICode.scala:61)
at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$applyPhase$$1.apply(Global.scala:326)
at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$applyPhase$$1.apply(Global.scala:326)
at scala.tools.nsc.reporters.Reporter.withSource(Reporter.scala:47)
at scala.tools.nsc.Global$$GlobalPhase.applyPhase(Global.scala:326)
at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$run$$1.apply(Global.scala:294)
at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$run$$1.apply(Global.scala:294)
at scala.collection.Iterator$$class.foreach(Iterator.scala:652)
at scala.collection.mutable.ListBuffer$$$$anon$$1.foreach(ListBuffer.scala:311)
at scala.tools.nsc.Global$$GlobalPhase.run(Global.scala:294)
at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.run(GenICode.scala:54)
at scala.tools.nsc.Global$$Run.compileSources(Global.scala:949)
at scala.tools.nsc.interpreter.IMain$$ReadEvalPrint.compileAndSaveRun(IMain.scala:636)
at scala.tools.nsc.interpreter.IMain$$ReadEvalPrint.compile(IMain.scala:604)
at scala.tools.nsc.interpreter.IMain$$Request.compile(IMain.scala:748)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:502)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:468)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$$1(ILoop.scala:724)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:775)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:677)
at scala.tools.nsc.interpreter.ILoop.processLine$$1(ILoop.scala:571)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:578)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:845)
at scala.tools.nsc.MainGenericRunner.runTarget$$1(MainGenericRunner.scala:67)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:80)
at scala.tools.nsc.MainGenericRunner$$.main(MainGenericRunner.scala:89)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) The last code example too. |
@soc said: |
@paulp said: |
Compare with
The text was updated successfully, but these errors were encountered: