-
Notifications
You must be signed in to change notification settings - Fork 597
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
Bundles with structurally typed fields in compatibility mode fail in Scala 2.12 #606
Comments
This is actually coming from a deeper issue with recent versions of the Scala compiler, going back at least to 2.12.0-M5 and also present in dotty, and actually has nothing to do with Chisel: scala> trait B {
| }
defined trait B
scala>
scala> trait BaseClass {
| val x : B
| }
defined trait BaseClass
scala>
scala> class MyClass extends BaseClass {
| val x = new B {
| val b = 0
| }
|
| x.b
| }
<console>:18: error: value b is not a member of B
x.b
^ It's probably introduced by #5141 or maybe even #5294 "Inferred types for fields" introduced in the 2.12 branch. It's quite interesting that the IO() macro somehow gets through with this issue. |
As mentioned here scala/bug#10047 and in "Inferred types for fields" on the 2.12.0 release notes (http://scala-lang.org/news/2.12.0/), this is intended behavior. Type inference has changed so the type of a structurally typed val is inferred to be the parent type rather than the structural type. Because scala> trait A
defined trait A
scala> abstract class B {
| val a: A
| }
defined class B
scala> class C extends B {
| def f[T <: A](a: T): a.type = a
| val a = f(new A {
| val foo = 3
| })
| }
defined class C
scala> val c = new C
c: C = C@72b59b59
scala> c.a.foo
res0: Int = 3 This can be worked around with the scalac option Assuming this workaround is general enough for large codebases like rocket chip, I think we should move forward with bumping to 2.12.3 and use the workaround for now. |
That plan of action sounds reasonable. Interesting that wrapping it in an IO(...) call is a workaround, is that something Scala might also remove in the future? |
Is this still relevant? It appears there's really nothing we can do on our end, and the IO(...) seems to solve this problem for relevant use cases. Compatibility code (rocket-chip) is basically the only issue, for which there is the described scalac option workaround. |
I think given that it's solved by To reiterate for posterity: Users of the compatibility wrapper should add the scalac option |
We mention this in the release notes.
…On Fri, Sep 22, 2017 at 3:31 PM, Jack Koenig ***@***.***> wrote:
I think given that it's solved by IO(...) this issue is closed from our
perspective.
To reiterate for posterity: Users of the compatibility wrapper should add
the scalac option -Xsource:2.11
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#606 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGh1wPcDTx0aFb3nZGU0ym57ZHkM3CH5ks5slDUvgaJpZM4NPrEx>
.
|
In the (very far...) future this problem will come again when Dotty is released. |
This is a problem again (and has been for a while now). #754 changed the type definition of // From
protected def IO[T<:Data](iodef: T): iodef.type
// To
protected def IO[T<:Data](iodef: T): T Returning |
Consider adding this as a 3.3 Issue |
This will be fixed in 3.5.0 once we delete |
Fixed in 3.5.0 |
Update (2019): this will continue to be an issue as structural types are going away in Scala 2.13/14+ and Scala 3.
Compiled with Scala 2.12, the following code:
produces
Wrapping the
io
definition inIO()
or extendingchisel3.core.UserModule
instead ofchisel3.core.LegacyModule
eliminates the error. It seems to be a property of theLegacyModule
definition.The text was updated successfully, but these errors were encountered: