Skip to content

Commit

Permalink
Fix retained flags in exports (#19636)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal authored Feb 6, 2024
2 parents 641ab7a + 1d4ca23 commit cba1cfc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
11 changes: 9 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,15 @@ object Flags {
/** Flags that can apply to a module class */
val RetainedModuleClassFlags: FlagSet = RetainedModuleValAndClassFlags | Enum

/** Flags retained in export forwarders */
val RetainedExportFlags = Given | Implicit | Inline | Transparent
/** Flags retained in term export forwarders */
val RetainedExportTermFlags = Infix | Given | Implicit | Inline | Transparent | Erased | HasDefaultParams | NoDefaultParams | ExtensionMethod

val MandatoryExportTermFlags = Exported | Method | Final

/** Flags retained in type export forwarders */
val RetainedExportTypeFlags = Infix

val MandatoryExportTypeFlags = Exported | Final

/** Flags that apply only to classes */
val ClassOnlyFlags = Sealed | Open | Abstract.toTypeFlags
Expand Down
9 changes: 3 additions & 6 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ class Namer { typer: Typer =>
target = target.etaExpand(target.typeParams)
newSymbol(
cls, forwarderName,
Exported | Final,
MandatoryExportTypeFlags | (sym.flags & RetainedExportTypeFlags),
TypeAlias(target),
coord = span)
// Note: This will always create unparameterzied aliases. So even if the original type is
Expand Down Expand Up @@ -1245,11 +1245,8 @@ class Namer { typer: Typer =>
then addPathMethodParams(pathMethod.info, mbr.info.widenExpr)
else mbr.info.ensureMethodic
(EmptyFlags, mbrInfo)
var flagMask = RetainedExportFlags
if sym.isTerm then flagMask |= HasDefaultParams | NoDefaultParams
var mbrFlags = Exported | Method | Final | maybeStable | sym.flags & flagMask
if sym.is(ExtensionMethod) || pathMethod.exists then
mbrFlags |= ExtensionMethod
var mbrFlags = MandatoryExportTermFlags | maybeStable | (sym.flags & RetainedExportTermFlags)
if pathMethod.exists then mbrFlags |= ExtensionMethod
val forwarderName = checkNoConflict(alias, isPrivate = false, span)
newSymbol(cls, forwarderName, mbrFlags, mbrInfo, coord = span)

Expand Down
12 changes: 12 additions & 0 deletions tests/pos/i19301.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//> using options -Xfatal-warnings

object Extensions:
infix def foo(x: String): Unit = ()
extension (arg1: Int) infix def X (arg2: Int): Int = arg1 * arg2
infix type X[A, B]

export Extensions.*

val x = 1 X 2
type Foo = Int X Int
val u = Extensions foo ""

0 comments on commit cba1cfc

Please sign in to comment.