From ef4888b87e38a796b0df3e959a0379481054104d Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 23 Jan 2024 09:14:05 +0100 Subject: [PATCH] Do not propagate `main` annotations to exported methods --- compiler/src/dotty/tools/dotc/typer/Namer.scala | 2 ++ tests/pos/export-main.scala | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 tests/pos/export-main.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 9f65f999d5e3..819b43fcec2c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1257,7 +1257,9 @@ class Namer { typer: Typer => forwarder.addAnnotations(sym.annotations.filterConserve { annot => annot.symbol != defn.BodyAnnot && annot.symbol != defn.TailrecAnnot + && annot.symbol != defn.MainAnnot && !annot.symbol.derivesFrom(defn.MacroAnnotationClass) + && !annot.symbol.derivesFrom(defn.MainAnnotationClass) }) if forwarder.isType then diff --git a/tests/pos/export-main.scala b/tests/pos/export-main.scala new file mode 100644 index 000000000000..7ce0a23de76f --- /dev/null +++ b/tests/pos/export-main.scala @@ -0,0 +1,5 @@ +object Foo: + @main def baz: Int = 1 + +object Bar: + export Foo.baz // export Foo.baz but not create an new main entry point