Skip to content

Teach Ycheck to spot references to Java packages #2456

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
DarkDimius opened this issue May 17, 2017 · 7 comments
Closed

Teach Ycheck to spot references to Java packages #2456

DarkDimius opened this issue May 17, 2017 · 7 comments

Comments

@DarkDimius
Copy link
Contributor

Ycheck should have complained here: #2396 (comment)

but it didn't.

@abeln
Copy link
Contributor

abeln commented May 24, 2017

@DarkDimius can you add a bit more context here?

  1. in which AST nodes can references to Java packages appear/not appear?
  2. is the answer to 1) true for all phases, or only after a specific phase?

@DarkDimius
Copy link
Contributor Author

@abeln,

  1. is hard to answer because we use Idents & Selects to represent Imports. So It's not about "in what trees", but instead about "in what context". Eg. packages should be passed as arguments or be assigned to variables.

The nice way to do it would be to introduce a phase after Pickler that gets rid of all references to packages in Select\Ident's. This phase should have a post-conditions that those trees don't re-appear.

@abeln
Copy link
Contributor

abeln commented May 24, 2017

Thanks. How do we "get rid" of references to Java packages? What should they be replaced with?

@DarkDimius
Copy link
Contributor Author

DarkDimius commented May 24, 2017

@abeln by replacing all verbose references that include packages by Idents.
Eg. Select(Select(Select(_root_, scala), Predef) println) => Ident(println)
After this, there should be no references to packages through RefTrees left.

@abeln
Copy link
Contributor

abeln commented May 24, 2017

Here's my understanding of what needs to be done:

  1. Declare a new MiniPhaseTransform, to be run together with Pickler (or after?)
  2. override transformSelect in the new mini-phase
  3. Within transformSelect, detect whether the qualifier stands for a package
  4. Simplify the Select node as you wrote above: (p1, p2, ..., pn).Ident(i) => Ident(i)

Is that reasonable?
If yes, then what's a good way to do step 3 (detecting whether a qualifier stands for a package)? The type of the qualifier is a TermRef (because packages are objects, right?), but how do I tell it apart from a "regular" object (otherwise I'll turn x.y.T into T)?

@DarkDimius
Copy link
Contributor Author

Is that reasonable?

Yes 👍

  1. after Pickler.
  2. yes.
  3. yes
  4. yes. Because the thing you refer to is top-level you can always refer to it through tpd.ref

If yes, then what's a good way to do step 3 (detecting whether a qualifier stands for a package)?

Take the term symbol of the qualifier. Check if it has both flags Package and JavaDefined set. I fou don't check for JavaDefined you can also get package objects.

abeln added a commit to abeln/dotty that referenced this issue May 24, 2017
@abeln
Copy link
Contributor

abeln commented May 24, 2017

Thanks. I took a first stab at this in #2528

abeln added a commit to abeln/dotty that referenced this issue May 31, 2017
After typechecking, replace TypeRefs trees of the form

Select(p, _) : tpe@TypeRef

where p refers to a Java package, by

Ident(tpe)
abeln added a commit to abeln/dotty that referenced this issue May 31, 2017
After typechecking, replace TypeRefs trees of the form

Select(p, _) : tpe@TypeRef

where p refers to a Java package, by

Ident(tpe)
DarkDimius added a commit that referenced this issue Jun 2, 2017
Fix #2456: eliminate syntactic references to Java packages
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 9, 2018
@Blaisorblade Blaisorblade changed the title Teach Ycheck to spot refernces to Java packages Teach Ycheck to spot references to Java packages Mar 9, 2018
odersky added a commit that referenced this issue Mar 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants