File tree Expand file tree Collapse file tree 4 files changed +38
-2
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 4 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ public enum ErrorMessageID {
64
64
MatchOnPhantomID ,
65
65
IfElsePhantomID ,
66
66
PhantomIsInObjectID ,
67
+ PhantomObjectIsInPackageOrObjectID ,
67
68
;
68
69
69
70
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -1296,4 +1296,12 @@ object messages {
1296
1296
val explanation =
1297
1297
hl """ | """ .stripMargin
1298
1298
}
1299
+
1300
+ case class PhantomObjectIsInPackageOrObject ()(implicit ctx : Context ) extends Message (PhantomObjectIsInPackageOrObjectID ) {
1301
+ val kind = " Phantom restriction"
1302
+ val msg = s " An ${" object" } extending ${" scala.Phantom" } must be a top level ${" object" } or in another object "
1303
+
1304
+ val explanation =
1305
+ hl """ | """ .stripMargin
1306
+ }
1299
1307
}
Original file line number Diff line number Diff line change @@ -1358,8 +1358,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1358
1358
cls, isRequired, cdef.pos)
1359
1359
}
1360
1360
1361
- if (! cls.is(Module ) && cls.classParents.exists(_.classSymbol eq defn.PhantomClass ))
1362
- ctx.error(PhantomIsInObject (), cdef.pos)
1361
+ if (cls.classParents.exists(_.classSymbol eq defn.PhantomClass )) {
1362
+ if (! cls.is(Module ))
1363
+ ctx.error(PhantomIsInObject (), cdef.pos)
1364
+ else if (! cls.owner.is(Module ) && ! cls.owner.is(Package ))
1365
+ ctx.error(PhantomObjectIsInPackageOrObject (), cdef.pos)
1366
+ }
1363
1367
1364
1368
// check value class constraints
1365
1369
checkDerivedValueClass(cls, body1)
Original file line number Diff line number Diff line change
1
+
2
+ class Foo {
3
+
4
+ object Boo1 extends Phantom // error
5
+
6
+ def foo = {
7
+ object Boo2 extends Phantom // error
8
+ 42
9
+ }
10
+ }
11
+
12
+ object Foo {
13
+ object Boo1 extends Phantom
14
+
15
+ def foo = {
16
+ object Boo2 extends Phantom // error
17
+ 42
18
+ }
19
+ }
20
+
21
+ package foo {
22
+ object Boo1 extends Phantom
23
+ }
You can’t perform that action at this time.
0 commit comments