8000 Multiple fixes to @static by DarkDimius · Pull Request #1226 · scala/scala3 · GitHub
[go: up one dir, main page]

Skip to content

Multiple fixes to @static #1226

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

Merged
merged 25 commits into from
Jun 22, 2016
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2e5ab54
Fix #1220. Dont die when having incorect static methods
DarkDimius Apr 18, 2016
7408f14
Test #1220
DarkDimius Apr 18, 2016
bbd48d3
SymDenotations: Allow entering Static symbols.
DarkDimius Apr 18, 2016
806a029
Constructors: do not lift static val initialisation into constructors.
DarkDimius Apr 18, 2016
db6a07d
Getters: do not generate getters for static vals
DarkDimius Apr 18, 2016
4ce8ab0
Allow creating static initialisers.
DarkDimius Apr 18, 2016
27846bb
MoveStatic: Move static methods & fields into companion class
DarkDimius Apr 18, 2016
63eb88d
Drop support for @static lazy vals.
DarkDimius Apr 18, 2016
ce2b964
Fix type in SymDenotations.
DarkDimius Apr 18, 2016
7cacd0f
Fix #1224: static members do not override\implement parent symbols.
DarkDimius Apr 18, 2016
1932b17
Test #1224.
DarkDimius Apr 18, 2016
f650b1e
LazyVals: do not share offsets between companions.
DarkDimius Apr 20, 2016
61fe99b
MoveStatics: fix two bugs.
DarkDimius Apr 20, 2016
d9702d2
Fix Ycheck: allow assigning fields in static constructors.
DarkDimius Apr 20, 2016
e1fcb4c
LazyVals: support debug mode.
DarkDimius Apr 20, 2016
990e962
SymDenotations: fix comment.
DarkDimius Apr 20, 2016
f2cfac5
MoveStatics: survive absence of companions.
DarkDimius Apr 20, 2016
fa6deee
DottyBackendInterface: fix a bug in methodSymbols.
DarkDimius Apr 20, 2016
5f73175
Add tests that were used to reproduce issues with LazyVals.
DarkDimius Apr 20, 2016
49ace48
MoveStatics: fix a bug.
DarkDimius Apr 20, 2016
2c6a9be
CheckStatic: report error position in case of disallowed override
DarkDimius Apr 20, 2016
9899a06
LazyVals: fix leftover moduleClass usage.
DarkDimius Apr 20, 2016
c428e74
LazyVals: do even more verbose debugging.
DarkDimius Jun 7, 2016
de45fa1
MoveStatics: Fix classes without companion not getting static <clinit>
DarkDimius Jun 7, 2016
3c93c5c
Make class initialisers private. Otherwise they break GenBCode.
DarkDimius Jun 7, 2016
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
Prev Previous commit
Next Next commit
MoveStatics: fix two bugs.
Unlink the static from the old scope,
and don't drop top-level trees that are not TypeDefs.
  • Loading branch information
DarkDimius committed Jun 7, 2016
commit 61fe99b6ad0fcd0a8402435cf15c504ce4b9c4ea
3 changes: 2 additions & 1 deletion src/dotty/tools/dotc/transform/MoveStatics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MoveStatics extends MiniPhaseTransform with SymTransformer { thisTransform

def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation = {
if (sym.hasAnnotation(defn.ScalaStaticAnnot) && sym.owner.is(Flags.Module)) {
sym.owner.asClass.delete(sym.symbol)
sym.owner.companionClass.asClass.enter(sym.symbol)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need to remove / unlink the symbol from the module's scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kind of intentionally not doing so.
To make sure it can be found in both places.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i don't know if that's a good idea (literally - maybe it is..)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note here we're already near the backend, so I'm preparing the tree specifically for GenBCode.
Phases that go in this block are backend-specific and break some assumptions of compiler.
Eg LabelDefs reorders <label> defs in a magical order that no one should touch.

Copy link
Member
@lrytz lrytz Apr 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it's related to exactly that discussion: the current PR creates a static field in both T and T$

import annotation.static
class T
object T {
  @static val x = 99
}
public class T {
  public static I x
}
public final class T$ {
  public static I x
}

the one in the module class is not initialized.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magical

✨ :)

val flags = if (sym.is(Flags.Method)) sym.flags else sym.flags | Flags.Mutable
sym.copySymDenotation(owner = sym.owner.companionClass, initFlags = flags)
Expand Down Expand Up @@ -58,7 +59,7 @@ class MoveStatics extends MiniPhaseTransform with SymTransformer { thisTransform
yield
if (classes.tail.isEmpty) classes.head
else move(classes.head, classes.tail.head)
Trees.flatten(newPairs.toList)
Trees.flatten(newPairs.toList ++ others)
} else trees
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe invert the condition and move this case up -- makes it easier to follow

}
}
0