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 treatment of separately compiled @native methods in FirstTransform #21593

Merged
merged 1 commit into from
Sep 14, 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
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ object Flags {
val ConstructorProxyModule: FlagSet = ConstructorProxy | Module
val DefaultParameter: FlagSet = HasDefault | Param // A Scala 2x default parameter
val DeferredInline: FlagSet = Deferred | Inline
val DeferredMethod: FlagSet = Deferred | Method
val DeferredOrLazy: FlagSet = Deferred | Lazy
val DeferredOrLazyOrMethod: FlagSet = Deferred | Lazy | Method
val DeferredOrTermParamOrAccessor: FlagSet = Deferred | ParamAccessor | TermParam // term symbols without right-hand sides
Expand Down
26 changes: 15 additions & 11 deletions compiler/src/dotty/tools/dotc/transform/FirstTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Decorators.*
import scala.collection.mutable
import DenotTransformers.*
import NameOps.*
import SymDenotations.SymDenotation
import NameKinds.OuterSelectName
import StdNames.*
import config.Feature
Expand All @@ -35,22 +36,26 @@ object FirstTransform {
* if (true) A else B ==> A
* if (false) A else B ==> B
*/
class FirstTransform extends MiniPhase with InfoTransformer { thisPhase =>
class FirstTransform extends MiniPhase with SymTransformer { thisPhase =>
import ast.tpd.*

override def phaseName: String = FirstTransform.name

override def description: String = FirstTransform.description

/** eliminate self symbol in ClassInfo */
override def transformInfo(tp: Type, sym: Symbol)(using Context): Type = tp match {
case tp @ ClassInfo(_, _, _, _, self: Symbol) =>
tp.derivedClassInfo(selfInfo = self.info)
case _ =>
tp
}

override protected def infoMayChange(sym: Symbol)(using Context): Boolean = sym.isClass
/** eliminate self symbol in ClassInfo, reset Deferred for @native methods */
override def transformSym(sym: SymDenotation)(using Context): SymDenotation =
if sym.isClass then
sym.info match
case tp @ ClassInfo(_, _, _, _, self: Symbol) =>
val info1 = tp.derivedClassInfo(selfInfo = self.info)
sym.copySymDenotation(info = info1).copyCaches(sym, ctx.phase.next)
case _ =>
sym
else if sym.isAllOf(DeferredMethod) && sym.hasAnnotation(defn.NativeAnnot) then
sym.copySymDenotation(initFlags = sym.flags &~ Deferred)
else
sym

override def checkPostCondition(tree: Tree)(using Context): Unit =
tree match {
Expand Down Expand Up @@ -121,7 +126,6 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase =>
override def transformDefDef(ddef: DefDef)(using Context): Tree =
val meth = ddef.symbol.asTerm
if meth.hasAnnotation(defn.NativeAnnot) then
meth.resetFlag(Deferred)
DefDef(meth, _ =>
ref(defn.Sys_error.termRef).withSpan(ddef.span)
.appliedTo(Literal(Constant(s"native method stub"))))
Expand Down
1 change: 1 addition & 0 deletions tests/pos/i20588/Baz_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class Baz extends Foo
3 changes: 3 additions & 0 deletions tests/pos/i20588/Foo_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Foo {
@native def test(): Unit
}
Loading