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 @@ -1299,4 +1299,12 @@ object messages {
1299
1299
val explanation =
1300
1300
hl """ | """ .stripMargin
1301
1301
}
1302
+
1303
+ case class PhantomObjectIsInPackageOrObject ()(implicit ctx : Context ) extends Message (PhantomObjectIsInPackageOrObjectID ) {
1304
+ val kind = " Phantom restriction"
1305
+ val msg = s " An ${" object" } extending ${" scala.Phantom" } must be a top level ${" object" } or in another object "
1306
+
1307
+ val explanation =
1308
+ hl """ | """ .stripMargin
1309
+ }
1302
1310
}
Original file line number Diff line number Diff line change @@ -1352,8 +1352,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1352
1352
cls, isRequired, cdef.pos)
1353
1353
}
1354
1354
1355
- if (! cls.is(Module ) && cls.classParents.exists(_.classSymbol eq defn.PhantomClass ))
1356
- ctx.error(PhantomIsInObject (), cdef.pos)
1355
+ if (cls.classParents.exists(_.classSymbol eq defn.PhantomClass )) {
1356
+ if (! cls.is(Module ))
1357
+ ctx.error(PhantomIsInObject (), cdef.pos)
1358
+ else if (! cls.owner.is(Module ) && ! cls.owner.is(Package ))
1359
+ ctx.error(PhantomObjectIsInPackageOrObject (), cdef.pos)
1360
+ }
1357
1361
1358
1362
// check value class constraints
1359
1363
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