forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not propagate
@tailrec
to exported methods (scala#19509)
Fixes scala#19505
- Loading branch information
Showing
6 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import scala.annotation.tailrec | ||
|
||
object Foo: | ||
@tailrec | ||
def foo(n: Int): Int = | ||
if n == 0 then 0 | ||
else foo(n-1) | ||
|
||
object Bar: | ||
export Foo.foo // def foo here should not have `@tailrec` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import scala.annotation.{experimental, MacroAnnotation} | ||
import scala.quoted._ | ||
import scala.collection.mutable.Map | ||
|
||
@experimental | ||
class returnClassName extends MacroAnnotation { | ||
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] = | ||
import quotes.reflect._ | ||
tree match | ||
case DefDef(name, params, tpt, _) => | ||
val rhs = Literal(StringConstant(Symbol.spliceOwner.name.stripSuffix("$"))) | ||
List(DefDef.copy(tree)(name, params, tpt, Some(rhs))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
object Bar: | ||
@returnClassName | ||
def f(): String = ??? // def f(): String = "Bar" | ||
|
||
object Baz: | ||
export Bar.f // def f(): String = Bar.f(n) | ||
|
||
@main def Test = | ||
assert(Bar.f() == "Bar") | ||
assert(Baz.f() == "Bar") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import scala.annotation.tailrec | ||
|
||
object Foo: | ||
@tailrec | ||
def foo: Int = foo // warn: Infinite recursive call | ||
|
||
object Bar: | ||
export Foo.foo // def foo here should not have `@tailrec` |