Skip to content

Commit 8b60f10

Browse files
Backport "Fix retained flags in exports" to LTS (#20912)
Backports #19636 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents f2428bd + 7bf4597 commit 8b60f10

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/Flags.scala

+9-2
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,15 @@ object Flags {
532532
/** Flags that can apply to a module class */
533533
val RetainedModuleClassFlags: FlagSet = RetainedModuleValAndClassFlags | Enum
534534

535-
/** Flags retained in export forwarders */
536-
val RetainedExportFlags = Given | Implicit | Inline | Transparent
535+
/** Flags retained in term export forwarders */
536+
val RetainedExportTermFlags = Infix | Given | Implicit | Inline | Transparent | Erased | HasDefaultParams | NoDefaultParams | ExtensionMethod
537+
538+
val MandatoryExportTermFlags = Exported | Method | Final
539+
540+
/** Flags retained in type export forwarders */
541+
val RetainedExportTypeFlags = Infix
542+
543+
val MandatoryExportTypeFlags = Exported | Final
537544

538545
/** Flags that apply only to classes */
539546
val ClassOnlyFlags = Sealed | Open | Abstract.toTypeFlags

Diff for: compiler/src/dotty/tools/dotc/typer/Namer.scala

+3-6
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ class Namer { typer: Typer =>
12001200
target = target.EtaExpand(target.typeParams)
12011201
newSymbol(
12021202
cls, forwarderName,
1203-
Exported | Final,
1203+
MandatoryExportTypeFlags | (sym.flags & RetainedExportTypeFlags),
12041204
TypeAlias(target),
12051205
coord = span)
12061206
// Note: This will always create unparameterzied aliases. So even if the original type is
@@ -1246,11 +1246,8 @@ class Namer { typer: Typer =>
12461246
then addPathMethodParams(pathMethod.info, mbr.info.widenExpr)
12471247
else mbr.info.ensureMethodic
12481248
(EmptyFlags, mbrInfo)
1249-
var flagMask = RetainedExportFlags
1250-
if sym.isTerm then flagMask |= HasDefaultParams | NoDefaultParams
1251-
var mbrFlags = Exported | Method | Final | maybeStable | sym.flags & flagMask
1252-
if sym.is(ExtensionMethod) || pathMethod.exists then
1253-
mbrFlags |= ExtensionMethod
1249+
var mbrFlags = MandatoryExportTermFlags | maybeStable | (sym.flags & RetainedExportTermFlags)
1250+
if pathMethod.exists then mbrFlags |= ExtensionMethod
12541251
val forwarderName = checkNoConflict(alias, isPrivate = false, span)
12551252
newSymbol(cls, forwarderName, mbrFlags, mbrInfo, coord = span)
12561253

Diff for: tests/pos/i19301.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//> using options -Xfatal-warnings
2+
3+
object Extensions:
4+
infix def foo(x: String): Unit = ()
5+
extension (arg1: Int) infix def X (arg2: Int): Int = arg1 * arg2
6+
infix type X[A, B]
7+
8+
export Extensions.*
9+
10+
val x = 1 X 2
11+
type Foo = Int X Int
12+
val u = Extensions foo ""

0 commit comments

Comments
 (0)