Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix retained flags in exports #19636

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ""
Loading