Skip to content

Commit cba1cfc

Browse files
authored
Fix retained flags in exports (#19636)
2 parents 641ab7a + 1d4ca23 commit cba1cfc

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

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

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

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

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)