-
Notifications
You must be signed in to change notification settings - Fork 21
unsoundness in many guises #7278
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
Comments
@paulp said (edited on Mar 20, 2013 8:46:26 PM UTC): [Update] I retitled this to point the unsoundness finger more vaguely, since martin says: "Same-named inner classes which are in no relationship with each other are explicitly allowed in both Java and Scala. I would like to tighten this - disallow then altogether or demand them to be in a subtype relationship. Unfortunately, this would break existing code [...] I believe they do not pose an unsoundness problem themselves. But they certainly are a trap to fall into in all sorts of feature interactions." [Update] After finding another soundness hole which doesn't use existentials, I consolidated the code and retitled it even more vaguely. |
@paulp said (edited on Mar 21, 2013 6:31:37 PM UTC): |
@paulp said: 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 |
@retronym said (edited on May 31, 2013 9:21:22 PM UTC): Code that provokes trait Def {
type Element >: Null
trait Motor {
type Element = Def.this.Element
}
}
trait Def2 extends Def {
trait Element
trait Motor extends super.Motor {
def foo(parent: Element): Any
foo(null)
}
}
trait Def3 extends Def2 {
trait Element // or extends super.Element2, same result.
new super.Motor {
def foo(e:Element): Any = null
}
}
new Def3 {} // java.lang.AbstractMethodError: Main$$anon$3$Def3$$anon$2.foo(LMain$$anon$3$Def2$Element;)Ljava/lang/Object Suggested: trait Def {
type Element >: Null
trait Motor {
type Element = Def.this.Element
}
}
trait Def2 extends Def {
type Element >: Null <: Element2
trait Element2
trait Motor extends super.Motor {
def foo(parent: Element): Any
foo(null)
}
}
trait Def3 extends Def2 {
type Element >: Null <: Element3
trait Element3 extends super.Element2
new super.Motor {
def foo(e:Element): Any = null
}
}
new Def3 {} |
@soc said: class Foo {
class Bar {
def foo = 1
}
}
class SubFoo extends Foo {
class Bar {
def foo = 42
}
}
// Let's create some instances:
val foo = new Foo
val fooBar = new foo.Bar
fooBar.foo //> res0: Int = 1
// ok
val subFoo = new SubFoo
val subFooBar = new subFoo.Bar
subFooBar.foo //> res1: Int = 42
// ok
val superFoo: Foo = subFoo
val superFooBar = new superFoo.Bar
superFooBar.foo //> res2: Int = 1
// NOT OK! The last result is scary, because the syntax looks like things are dynamically bound, but the method is called on the static type instead. Mailing list: https://groups.google.com/d/topic/scala-language/vQYwywr0LL4/discussion |
Scala 3 refuses to compile It also rejects As for the status of these various examples in Scala 2, I think one reason this ticket has stayed open so long is it combines a lot of different stuff. I don't understand what the motivation was to consolidate all this in a single ticket — and then it got bigger as people have piled on with comments. In recent years we have been more consistent about discouraging these sorts of umbrella tickets. If anyone cares about some individual case here, I invite you to open a fresh ticket on it, so we can discuss it independently, label it independently, attempt to reproduce it in Scala 2.13.x and Scala 3 independently, and so forth. |
Instead of a fresh ticket, I reopened 7535, which now shows green above. |
The example from the mailing seems OK to me, but the thread shows that the expectation at the time was virtual classes. It warns on 2.13 and errors under
The paulp coda still crashes.
It can be "made to work" by the (probably expected) idiom
|
[Updated to consolidate demonstrations.]
The text was updated successfully, but these errors were encountered: