Skip to content

Commit 82415ca

Browse files
hamzaremmalWojciechMazur
authored andcommitted
Allow export statements in AnyVal
[Cherry-picked d2cf0fb]
1 parent e2b0ec8 commit 82415ca

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

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)