Skip to content

Reference to wrongly declared static value #10817

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

Closed
prolativ opened this issue Dec 16, 2020 · 0 comments · Fixed by #10818
Closed

Reference to wrongly declared static value #10817

prolativ opened this issue Dec 16, 2020 · 0 comments · Fixed by #10818

Comments

@prolativ
Copy link
Contributor

Minimized code

import annotation.static

class T:
  @static val foo = 10

val x = (new T).foo

Output (click arrow to expand)

-- [E109] Syntax Error: /var/folders/rp/f9y80jvs54lcy26rxnt2y2kw0000gn/T/test.scala:4:14 
4 |  @static val foo = 10
  |  ^^^^^^^^^^^^^^^^^^^^
  |  @static value foo in class T must be defined inside an object.

longer explanation available when compiling with `-explain`
exception occurred while compiling /var/folders/rp/f9y80jvs54lcy26rxnt2y2kw0000gn/T/test.scala
scala.MatchError: Apply(Select(New(TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class T)]),<init>),List()) (of class dotty.tools.dotc.ast.Trees$Apply) while compiling /var/folders/rp/f9y80jvs54lcy26rxnt2y2kw0000gn/T/test.scala
Exception in thread "main" scala.MatchError: Apply(Select(New(TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class T)]),<init>),List()) (of class dotty.tools.dotc.ast.Trees$Apply)
        at dotty.tools.dotc.transform.CheckStatic.isSafeQual$1(CheckStatic.scala:70)
        at dotty.tools.dotc.transform.CheckStatic.transformSelect(CheckStatic.scala:72)
        at dotty.tools.dotc.transform.MegaPhase.goSelect(MegaPhase.scala:599)
        at dotty.tools.dotc.transform.MegaPhase.goSelect(MegaPhase.scala:600)
        at dotty.tools.dotc.transform.MegaPhase.goSelect(MegaPhase.scala:600)
        at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:229)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
        at dotty.tools.dotc.transform.MegaPhase.mapValDef$1(MegaPhase.scala:235)
        at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:240)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
        at dotty.tools.dotc.transform.MegaPhase.transformStat$2(MegaPhase.scala:437)
        at dotty.tools.dotc.transform.MegaPhase.recur$1(MegaPhase.scala:442)
        at dotty.tools.dotc.transform.MegaPhase.recur$1(MegaPhase.scala:1061)
        at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:442)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:362)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:429)
        at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:256)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:427)
        at dotty.tools.dotc.transform.MegaPhase.transformStat$2(MegaPhase.scala:437)
        at dotty.tools.dotc.transform.MegaPhase.recur$1(MegaPhase.scala:442)
        at dotty.tools.dotc.transform.MegaPhase.recur$1(MegaPhase.scala:1061)
        at dotty.tools.dotc.transform.MegaPhase.recur$1(MegaPhase.scala:1061)
        at dotty.tools.dotc.transform.MegaPhase.recur$1(MegaPhase.scala:1061)
        at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:442)
        at dotty.tools.dotc.transform.MegaPhase.mapPackage$1(MegaPhase.scala:382)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:385)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:429)
        at dotty.tools.dotc.transform.MegaPhase.transformUnit(MegaPhase.scala:448)
        at dotty.tools.dotc.transform.MegaPhase.run(MegaPhase.scala:460)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:296)
        at dotty.tools.dotc.core.Phases$Phase$$Lambda$677/000000000000000000.apply(Unknown Source)
        at scala.collection.immutable.List.map(List.scala:246)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:297)
        at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:185)
        at dotty.tools.dotc.Run$$Lambda$357/000000000000000000.applyVoid(Unknown Source)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
        at dotty.tools.dotc.Run.runPhases$5(Run.scala:195)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:203)
        at dotty.tools.dotc.Run$$Lambda$317/000000000000000000.apply$mcV$sp(Unknown Source)
        at scala.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:210)
        at dotty.tools.dotc.Run.compileSources(Run.scala:146)
        at dotty.tools.dotc.Run.compile(Run.scala:130)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:39)
        at dotty.tools.dotc.Driver.process(Driver.scala:186)
        at dotty.tools.dotc.Driver.process(Driver.scala:155)
        at dotty.tools.dotc.Driver.process(Driver.scala:167)
        at dotty.tools.dotc.Driver.main(Driver.scala:194)
        at dotty.tools.dotc.Main.main(Main.scala)

The error on the declaration is correct but an attempt to refer to the value shouldn't crash the compiler.

odersky added a commit to dotty-staging/dotty that referenced this issue Dec 16, 2020
odersky added a commit that referenced this issue Dec 23, 2020
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants