Skip to content

Commit ebf1065

Browse files
Merge pull request #7 from scala/backport-lts-3.3-21653
Backport "Allow export statements in AnyVal" to LTS
2 parents 7737555 + 82415ca commit ebf1065

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import printing.Formatting.hl
1919
import config.Printers
2020

2121
import scala.annotation.internal.sharable
22+
import dotty.tools.dotc.util.SrcPos
2223

2324
object desugar {
2425
import untpd.*

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ object Checking {
708708
report.error(ValueClassesMayNotDefineNonParameterField(clazz, stat.symbol), stat.srcPos)
709709
case _: DefDef if stat.symbol.isConstructor =>
710710
report.error(ValueClassesMayNotDefineASecondaryConstructor(clazz, stat.symbol), stat.srcPos)
711-
case _: MemberDef | _: Import | EmptyTree =>
711+
case _: MemberDef | _: Import | _: Export | EmptyTree =>
712712
// ok
713713
case _ =>
714714
report.error(ValueClassesMayNotContainInitalization(clazz), stat.srcPos)

tests/run/export-anyval.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello from export

tests/run/export-anyval.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Foo(val x: String)
2+
3+
4+
class Bar(val y: Foo) extends AnyVal:
5+
export y.*
6+
def foo: String = x
7+
end Bar
8+
9+
@main def Test =
10+
val a = Bar(Foo("Hello from export"))
11+
println(a.foo)
12+

0 commit comments

Comments
 (0)