Skip to content

Commit 0fb7efc

Browse files
Merge pull request #7436 from dotty-staging/fix-#7428
Fix #7428: Don't make enum values JavaStatic
2 parents 5e8e26f + aa3b1cd commit 0fb7efc

File tree

4 files changed

+28
-29
lines changed

4 files changed

+28
-29
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/core/Flags.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ object Flags {
526526
val DeferredOrLazyOrMethod: FlagSet = Deferred | Lazy | Method
527527
val DeferredOrTermParamOrAccessor: FlagSet = Deferred | ParamAccessor | TermParam // term symbols without right-hand sides
528528
val DeferredOrTypeParam: FlagSet = Deferred | TypeParam // type symbols without right-hand sides
529-
val EnumValue: FlagSet = Enum | JavaStatic | StableRealizable // A Scala enum value
529+
val EnumValue: FlagSet = Enum | StableRealizable // A Scala enum value
530530
val StableOrErased: FlagSet = Erased | StableRealizable // Assumed to be pure
531531
val ExtensionMethod: FlagSet = Extension | Method
532532
val FinalOrInline: FlagSet = Final | Inline

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)

tests/pos/i7428.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class ABug
2+
enum Tag
3+
case first
4+
import Tag.first
5+
val xx = first
6+

0 commit comments

Comments
 (0)