Skip to content

Conversation

@retronym
Copy link
Member

No description provided.

@retronym
Copy link
Member Author

Targetting at 2.13.x, but this would be a backport candidate for 2.12.9

retronym and others added 4 commits February 11, 2019 11:02
For static innner classes, we need to check in the companion
module of each base classes.
to avoid cluttering logic that 99% of time deals with Scala
@adriaanm adriaanm force-pushed the topic/java-inherited-type-ident branch from 7b3790e to 29fe15b Compare February 11, 2019 13:57
Copy link
Contributor

@adriaanm adriaanm left a comment

Choose a reason for hiding this comment

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

I push -f'ed my review (just a small tweak). Let me know if this looks good to you. Let's squash the commits before merging.

@retronym retronym merged commit fbd1788 into scala:2.13.x Feb 11, 2019
retronym added a commit to retronym/scala that referenced this pull request Feb 12, 2019
 - Inherited type declarations are in scope in Java code
 - For static innner classes, we need to check in the companion
module of each base classes.
 - Incorporate and accomodate test case from scala#6053
 - Tests to java code referring to module-class owned classes via companion class prefix

 Backport of scala#7671
@retronym
Copy link
Member Author

Backport submitted in #7738

retronym added a commit to retronym/scala that referenced this pull request Feb 12, 2019
 - Inherited type declarations are in scope in Java code
 - For static innner classes, we need to check in the companion
module of each base classes.
 - Incorporate and accomodate test case from scala#6053
 - Tests to java code referring to module-class owned classes via companion class prefix

 Backport of scala#7671
@som-snytt
Copy link
Contributor

"Java rules!"

@adriaanm
Copy link
Contributor

Awesome -- this also obviates the need for a leaky encoding in JavaParsers:

def forwarders(sdef: Tree): List[Tree] = sdef match {
case ClassDef(mods, name, tparams, _) if (parentToken == INTERFACE) =>
val tparams1: List[TypeDef] = tparams map (_.duplicate)
var rhs: Tree = Select(Ident(parentName.toTermName), name)
if (!tparams1.isEmpty) rhs = AppliedTypeTree(rhs, tparams1 map (tp => Ident(tp.name)))
List(TypeDef(Modifiers(Flags.PROTECTED), name, tparams1, rhs))
case _ =>
List()
}
val sdefs = statics.toList
val idefs = members.toList ::: (sdefs flatMap forwarders)

Those forwarders attempt to encode the rules that this PR implements directly. They cause issues when refchecks becomes more accurate because they are inherited.

adriaanm added a commit to adriaanm/scala that referenced this pull request Mar 21, 2019
It's subsumed by Jason's improvements to name resolution in scala#7671.

The leak yielded spurious errors in mixed Scala/Java compilation (akka-http).

Also, pull up exemption for synthetic members from refchecks; it makes no
sense to bother the user about members synthesized by the compiler.

We could get early warnings this way, but eventually they'll pop up
as VerifyErrors...
adriaanm added a commit to adriaanm/scala that referenced this pull request Mar 21, 2019
It's subsumed by Jason's improvements to name resolution in scala#7671.

The leak yielded spurious errors in mixed Scala/Java compilation (akka-http).
retronym pushed a commit to retronym/scala that referenced this pull request May 23, 2019
It's subsumed by Jason's improvements to name resolution in scala#7671.

The leak yielded spurious errors in mixed Scala/Java compilation (akka-http).

(cherry picked from commit 8529be7)
retronym added a commit to retronym/scala that referenced this pull request Jun 19, 2019
Fixed in scala#7671, which was backported to 2.12.x in scala#7738
i10416 added a commit to i10416/dotty that referenced this pull request Feb 24, 2024
To find Scala companion mudule from Java in mixed sources,
we should strip module suffix `$`.
This provides workaround for scala#17255, but it requires some refinment to fix it
because not-fully-qualified type like the following example still fails
to compile due to missing symbol.

```java
package example;

public class Bar {
    private static final Foo$ MOD = Foo$.MODULE;
}
```

This is because `pre` in `javaFindMember` for `Foo` in the case above is `<root>`,
not `example` and therefore `pre.findMember` looks for `<root>.Foo` instead
of `example.Foo`.

I'm not sure whether the qualifier is intentionally dropped.

References
- scala#12884
- scala/scala#7671
WojciechMazur added a commit to scala/scala3 that referenced this pull request Jul 2, 2024
To find Scala companion mudule from Java in mixed sources,
we should strip module suffix `$`.
This provides workaround for #17255, but it requires some refinment to fix it
because not-fully-qualified type like the following example still fails
to compile due to missing symbol.

```java
package example;

public class Bar {
    private static final Foo$ MOD = Foo$.MODULE;
}
```

This is because `pre` in `javaFindMember` for `Foo` in the case above is `<root>`,
not `example` and therefore `pre.findMember` looks for `<root>.Foo` instead
of `example.Foo`.

I'm not sure whether the qualifier is intentionally dropped.

References
- #12884
- scala/scala#7671

[Cherry-picked 22d98d6][modified]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants