Skip to content

Commit 9961e70

Browse files
authored
Allow export statements in AnyVal (#21653)
2 parents 5ec1e8b + d2cf0fb commit 9961e70

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ object Checking {
727727
report.error(ValueClassesMayNotDefineNonParameterField(clazz, stat.symbol), stat.srcPos)
728728
case _: DefDef if stat.symbol.isConstructor =>
729729
report.error(ValueClassesMayNotDefineASecondaryConstructor(clazz, stat.symbol), stat.srcPos)
730-
case _: MemberDef | _: Import | EmptyTree =>
730+
case _: MemberDef | _: Import | _: Export | EmptyTree =>
731731
// ok
732732
case _ =>
733733
report.error(ValueClassesMayNotContainInitalization(clazz), stat.srcPos)

tests/run/export-anyval.check

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello from export

tests/run/export-anyval.scala

+12
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)