File tree Expand file tree Collapse file tree 8 files changed +34
-7
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 8 files changed +34
-7
lines changed Original file line number Diff line number Diff line change @@ -169,7 +169,8 @@ enum ErrorMessageID extends java.lang.Enum[ErrorMessageID] {
169
169
InvalidReferenceInImplicitNotFoundAnnotationID ,
170
170
TraitMayNotDefineNativeMethodID ,
171
171
JavaEnumParentArgsID ,
172
- AlreadyDefinedID
172
+ AlreadyDefinedID ,
173
+ CaseClassInInlinedCodeID
173
174
174
175
def errorNumber = ordinal - 2
175
176
}
Original file line number Diff line number Diff line change @@ -2500,3 +2500,14 @@ import transform.SymUtils._
2500
2500
| """ .stripMargin
2501
2501
def explain = " "
2502
2502
}
2503
+
2504
+ class CaseClassInInlinedCode (tree : tpd.Tree )(using Context )
2505
+ extends SyntaxMsg (CaseClassInInlinedCodeID ) {
2506
+
2507
+ def defKind = if tree.symbol.is(Module ) then " object" else " class"
2508
+ def msg = s " Case $defKind definitions are not allowed in inline methods or quoted code. Use a normal $defKind instead. "
2509
+ def explain =
2510
+ em """ Case class/object definitions generate have a considerable fooprint in code size the to all the generated methods.
2511
+ |Inlining such definition would multiply this footprint.
2512
+ | """ .stripMargin
2513
+ }
Original file line number Diff line number Diff line change @@ -93,7 +93,9 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
93
93
checkAnnotations(tree)
94
94
healInfo(tree, tree.srcPos)
95
95
super .transform(tree)
96
-
96
+ case tree : TypeDef if tree.symbol.is(Case ) && level > 0 =>
97
+ report.error(reporting.CaseClassInInlinedCode (tree), tree)
98
+ super .transform(tree)
97
99
case _ =>
98
100
super .transform(tree)
99
101
}
Original file line number Diff line number Diff line change @@ -177,7 +177,11 @@ object PrepareInlineable {
177
177
// myAccessors += TypeDef(accessor).withPos(tree.pos.focus)
178
178
// ref(accessor).withSpan(tree.span)
179
179
//
180
- case _ => tree
180
+ case _ : TypeDef if tree.symbol.is(Case ) =>
181
+ report.error(reporting.CaseClassInInlinedCode (tree), tree)
182
+ tree
183
+ case _ =>
184
+ tree
181
185
}
182
186
}
183
187
@@ -251,7 +255,7 @@ object PrepareInlineable {
251
255
}
252
256
}
253
257
254
- def checkInlineMethod (inlined : Symbol , body : Tree )(using Context ): body.type = {
258
+ private def checkInlineMethod (inlined : Symbol , body : Tree )(using Context ): body.type = {
255
259
if (inlined.owner.isClass && inlined.owner.seesOpaques)
256
260
report.error(em " Implementation restriction: No inline methods allowed where opaque type aliases are in scope " , inlined.srcPos)
257
261
if Inliner .inInlineMethod(using ctx.outer) then
Original file line number Diff line number Diff line change 1
1
import scala .quoted ._
2
2
def test (using Quotes ) = {
3
- ' { case class Foo () }
3
+ ' { case class Foo () } // error
4
4
}
Original file line number Diff line number Diff line change
1
+ def species (using quoted.Quotes ) = ' {
2
+ case object Bar // error
3
+ case class FooT () // error
4
+ $ {
5
+ case object Baz // ok
6
+ ???
7
+ }
8
+ FooT ()
9
+ }
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ sealed trait Foo[T] {
3
3
}
4
4
5
5
inline def species [T ](t : T ) = {
6
- case class FooT (x : T ) extends Foo [T ] {
6
+ case class FooT (x : T ) extends Foo [T ] { // error
7
7
def foo (s : Foo [T ]) = s match {
8
8
case FooT (x) => ???
9
9
}
Original file line number Diff line number Diff line change 1
1
inline def species () = {
2
- case class FooT ()
2
+ case class FooT () // error
3
3
FooT ()
4
4
}
5
5
val foo = species()
You can’t perform that action at this time.
0 commit comments