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

Overly permissive overriding allowed in refinements: unsound #963

Closed
scabug opened this issue May 25, 2008 · 9 comments
Closed

Overly permissive overriding allowed in refinements: unsound #963

scabug opened this issue May 25, 2008 · 9 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented May 25, 2008

scala> import scala.util.Random
import scala.util.Random

scala> val r = new Random()
r: Random = scala.Random@1b3d448

scala> val y : { val x : java.lang.Integer  } = new { def x = new java.lang.Integer(r.nextInt) }
y: AnyRef{def x: java.lang.Integer} = $$anon$$1@e8709d

scala> val w1 : y.x.type = y.x
w1: y.x.type = 16667032

scala> val w2 : y.x.type = y.x
w2: y.x.type = -1279252109

scala> w1 == w2
res6: Boolean = false

Compare with

scala> class Foo {
     |   def x = new java.lang.Integer(r.nextInt)
     | }
defined class Foo

scala> val f = new Foo
f: Foo = Foo@db71e4

scala> val u1 : f.x.type = f.x
<console>:7: error: stable identifier required, but f.x found.
       val u1 : f.x.type = f.x
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 25, 2008

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

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 27, 2008

@dragos said:
I wonder why the def x is allowed to implement val x in the first line of your example..

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jan 14, 2009

@odersky said:
Milestone next_bugfix deleted

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 3, 2010

@paulp said:
I see I didn't attach the source to the ticket way back when, but since it's still not fixed maybe I'd better. This is a soundness bug: here is CCE inducing source.

// 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)
}
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 5, 2010

@dubochet said:
Before closing, check that it also solves (presumed duplicate) #2079.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Mar 8, 2011

@paulp said:
Punting down the road just a littttle further.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 10, 2011

@soc said:
This now crashes the compiler:

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.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 18, 2011

@soc said:
In 2.10.0.r25248-b20110707020221 things compile again ...

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 4, 2012

@paulp said:
01f6ed8e22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.