Skip to content

Commit 1045571

Browse files
committed
Retain default parameters with export
Default parameters need to have the `HasDefault` flag set to work properly, it seems that without this flag they were still selected but only under join compilation. While we're at it, we define a full set of flags that might be exported. Note that Given/Implicit/Erased were already set by `tpd.DefDef` and Inlined doesn't seem to make a difference in practice since the body of the exported inline def is manually constructed and doesn't contain proxies either way.
1 parent c7570c8 commit 1045571

File tree

6 files changed

+31
-1
lines changed

6 files changed

+31
-1
lines changed

compiler/src/dotty/tools/dotc/core/Flags.scala

+3
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,9 @@ object Flags {
535535
/** Flags retained in term export forwarders */
536536
val RetainedExportTermFlags = Infix | Given | Implicit | Inline | Transparent | Erased | HasDefaultParams | NoDefaultParams | ExtensionMethod
537537

538+
/** Flags retained in parameters of term export forwarders */
539+
val RetainedExportTermParamFlags = Given | Implicit | Erased | HasDefault | Inline
540+
538541
val MandatoryExportTermFlags = Exported | Method | Final
539542

540543
/** Flags retained in type export forwarders */

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1293,14 +1293,16 @@ class Namer { typer: Typer =>
12931293
getter => addForwarder(
12941294
getter.name.asTermName, getter.asSeenFrom(path.tpe), span))
12951295

1296-
// adding annotations at the parameter level
1296+
// adding annotations and flags at the parameter level
12971297
// TODO: This probably needs to be filtered to avoid adding some annotation
12981298
// such as MacroAnnotations
12991299
if sym.is(Method) then
13001300
for (orig, forwarded) <- sym.paramSymss.lazyZip(forwarder.paramSymss)
13011301
(origParameter, exportedParameter) <- orig.lazyZip(forwarded)
13021302
do
13031303
exportedParameter.addAnnotations(origParameter.annotations)
1304+
if exportedParameter.isTerm then
1305+
exportedParameter.setFlag(origParameter.flags & RetainedExportTermParamFlags)
13041306
end addForwarder
13051307

13061308
def addForwardersNamed(name: TermName, alias: TermName, span: Span): Unit =
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object A:
2+
def defaultParam(x: Int = 1) = x
3+
4+
object Exported:
5+
export A.*
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
object B:
2+
val x = Exported.defaultParam()
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[[syntax trees at end of typer]] // tests/printing/export-param-flags.scala
2+
package <empty> {
3+
final lazy module val A: A = new A()
4+
final module class A() extends Object() { this: A.type =>
5+
inline def inlinedParam(inline x: Int): Int = x.+(x):Int
6+
}
7+
final lazy module val Exported: Exported = new Exported()
8+
final module class Exported() extends Object() { this: Exported.type =>
9+
export A.*
10+
final inline def inlinedParam(inline x: Int): Int = A.inlinedParam(x)
11+
}
12+
}
13+
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object A:
2+
inline def inlinedParam(inline x: Int): Int = x + x
3+
4+
object Exported:
5+
export A.*

0 commit comments

Comments
 (0)