Skip to content

Commit aa3b1cd

Browse files
committed
Set JavaStatic flag for enum values at Namer
1 parent 23d414b commit aa3b1cd

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -274,23 +274,6 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]
274274
case _ => tree
275275
}
276276

277-
/** True iff definition is a val or def with no right-hand-side, or it
278-
* is an abstract typoe declaration
279-
*/
280-
def lacksDefinition(mdef: MemberDef)(implicit ctx: Context): Boolean = mdef match {
281-
case mdef: ValOrDefDef =>
282-
mdef.unforcedRhs == EmptyTree && !mdef.name.isConstructorName && !mdef.mods.isOneOf(TermParamOrAccessor)
283-
case mdef: TypeDef =>
284-
def isBounds(rhs: Tree): Boolean = rhs match {
285-
case _: TypeBoundsTree => true
286-
case _: MatchTypeTree => true // Typedefs with Match rhs classify as abstract
287-
case LambdaTypeTree(_, body) => isBounds(body)
288-
case _ => false
289-
}
290-
mdef.rhs.isEmpty || isBounds(mdef.rhs)
291-
case _ => false
292-
}
293-
294277
def functionWithUnknownParamType(tree: Tree): Option[Tree] = tree match {
295278
case Function(args, _) =>
296279
if (args.exists {

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,8 @@ class Erasure extends Phase with DenotTransformer {
7575
val newInfo = transformInfo(oldSymbol, oldInfo)
7676
val oldFlags = ref.flags
7777
val newFlags =
78-
if oldSymbol.is(Flags.TermParam) && isCompacted(oldSymbol.owner) then
79-
oldFlags &~ Flags.Param
80-
else if oldSymbol.isAllOf(Flags.EnumValue) && oldSymbol.isStatic then
81-
oldFlags | Flags.JavaStatic
82-
else
83-
oldFlags &~ Flags.HasDefaultParamsFlags // HasDefaultParamsFlags needs to be dropped because overriding might become overloading
78+
if (oldSymbol.is(Flags.TermParam) && isCompacted(oldSymbol.owner)) oldFlags &~ Flags.Param
79+
else oldFlags &~ Flags.HasDefaultParamsFlags // HasDefaultParamsFlags needs to be dropped because overriding might become overloading
8480

8581
// TODO: define derivedSymDenotation?
8682
if ((oldSymbol eq newSymbol) && (oldOwner eq newOwner) && (oldName eq newName) && (oldInfo eq newInfo) && (oldFlags == newFlags))

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,25 @@ class Namer { typer: Typer =>
352352
cls
353353
case tree: MemberDef =>
354354
val name = checkNoConflict(tree.name)
355-
val flags = checkFlags(tree.mods.flags)
356-
val isDeferred = lacksDefinition(tree)
357-
val deferred = if (isDeferred) Deferred else EmptyFlags
358-
val method = if (tree.isInstanceOf[DefDef]) Method else EmptyFlags
359-
val higherKinded = tree match {
360-
case TypeDef(_, LambdaTypeTree(_, _)) if isDeferred => HigherKinded
361-
case _ => EmptyFlags
362-
}
355+
var flags = checkFlags(tree.mods.flags)
356+
tree match
357+
case tree: ValOrDefDef =>
358+
if tree.unforcedRhs == EmptyTree
359+
&& !flags.isOneOf(TermParamOrAccessor)
360+
&& !tree.name.isConstructorName
361+
then
362+
flags |= Deferred
363+
if (tree.isInstanceOf[DefDef]) flags |= Method
364+
else if flags.isAllOf(EnumValue) && ctx.owner.isStaticOwner then flags |= JavaStatic
365+
case tree: TypeDef =>
366+
def analyzeRHS(rhs: Tree): Unit = rhs match
367+
case _: TypeBoundsTree | _: MatchTypeTree =>
368+
flags |= Deferred // Typedefs with Match rhs classify as abstract
369+
case LambdaTypeTree(_, body) =>
370+
flags |= HigherKinded
371+
analyzeRHS(body)
372+
case _ =>
373+
if tree.rhs.isEmpty then flags |= Deferred else analyzeRHS(tree.rhs)
363374

364375
// to complete a constructor, move one context further out -- this
365376
// is the context enclosing the class. Note that the context in which a
@@ -370,7 +381,7 @@ class Namer { typer: Typer =>
370381
// Don't do this for Java constructors because they need to see the import
371382
// of the companion object, and it is not necessary for them because they
372383
// have no implementation.
373-
val cctx = if (tree.name == nme.CONSTRUCTOR && !tree.mods.is(JavaDefined)) ctx.outer else ctx
384+
val cctx = if (tree.name == nme.CONSTRUCTOR && !flags.is(JavaDefined)) ctx.outer else ctx
374385

375386
val completer = tree match {
376387
case tree: TypeDef =>
@@ -380,8 +391,7 @@ class Namer { typer: Typer =>
380391
new Completer(tree)(cctx)
381392
}
382393
val info = adjustIfModule(completer, tree)
383-
createOrRefine[Symbol](tree, name, flags | deferred | method | higherKinded,
384-
ctx.owner, _ => info,
394+
createOrRefine[Symbol](tree, name, flags, ctx.owner, _ => info,
385395
(fs, _, pwithin) => ctx.newSymbol(ctx.owner, name, fs, info, pwithin, tree.nameSpan))
386396
case tree: Import =>
387397
recordSym(ctx.newImportSymbol(ctx.owner, new Completer(tree), tree.span), tree)

0 commit comments

Comments
 (0)