Skip to content

Self Type shadows constructor arguments. #3861

Closed
@scabug

Description

@scabug

It seems that the self-type annotation shadows constructor arguments.

$$ scala
Welcome to Scala version 2.8.1.RC1 (Java HotSpot(TM) Client VM, Java 1.6.0_16).
Type in expressions to have them evaluated.
Type :help for more information.

scala> trait Y
defined trait Y

scala> abstract class X(x: Int) { self: Y => x }
<console>:6: error: not found: value x
       abstract class X(x: Int) { self: Y => x }
                                             ^

Of course, without self-type annotation, there is no problem,

scala> abstract class X(x: Int) { self => x }
defined class X

and curiously there is no problem with 'val',

scala> abstract class X(val x: Int) { self: Y => x }
defined class X

This problem, for example, will cause the following unexpected result,

scala> object X {
     |   val x: Int = 1
     |   trait Y
     |   abstract class XX(x: Int){ self: Y =>
     |     println(x)
     |   }
     |   new XX(2) with Y
     | }
defined module X
scala> X
1
res0: X.type = X$$@1df3082

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions