Skip to content

Commit

Permalink
Allow export statements in AnyVal
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal committed Sep 27, 2024
1 parent a9fd5b8 commit d2cf0fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ object Checking {
report.error(ValueClassesMayNotDefineNonParameterField(clazz, stat.symbol), stat.srcPos)
case _: DefDef if stat.symbol.isConstructor =>
report.error(ValueClassesMayNotDefineASecondaryConstructor(clazz, stat.symbol), stat.srcPos)
case _: MemberDef | _: Import | EmptyTree =>
case _: MemberDef | _: Import | _: Export | EmptyTree =>
// ok
case _ =>
report.error(ValueClassesMayNotContainInitalization(clazz), stat.srcPos)
Expand Down
1 change: 1 addition & 0 deletions tests/run/export-anyval.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello from export
12 changes: 12 additions & 0 deletions tests/run/export-anyval.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Foo(val x: String)


class Bar(val y: Foo) extends AnyVal:
export y.*
def foo: String = x
end Bar

@main def Test =
val a = Bar(Foo("Hello from export"))
println(a.foo)

0 comments on commit d2cf0fb

Please sign in to comment.