Skip to content

Type not found when reference static type in java parent class #10956

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
changvvb opened this issue Dec 31, 2020 · 7 comments
Closed

Type not found when reference static type in java parent class #10956

changvvb opened this issue Dec 31, 2020 · 7 comments

Comments

@changvvb
Copy link
Contributor

Minimized code

java code

abstract class Foo {
    public static final class Inner { }
}

class Bar extends Foo {
    Inner i = new Inner();
}

Output

-- [E006] Not Found Error: Test.java:6:4 ---------------------------------------
6 |    Inner i = new Inner();
  |    ^^^^^
  |    Not found: type Inner

longer explanation available when compiling with `-explain`
1 error found

Expectation

I think this should be compiled because javac compiles the code successfully.

@changvvb
Copy link
Contributor Author

similar with scala/bug#9111

@changvvb changvvb changed the title Type not found where reference static type in parent java class Type not found when reference static type in java parent class Dec 31, 2020
@odersky
Copy link
Contributor

odersky commented Jan 1, 2021

This does not need fixing. Class Inner is static and therefore conceptually part of the companion object of Foo. So it is not in scope for extending classes.

@odersky odersky closed this as completed Jan 1, 2021
@changvvb
Copy link
Contributor Author

changvvb commented Jan 1, 2021

I understand. But java protocol buffers use this kind of code, so scala3 can not compile the java files generated by protoc.
scala/bug#9111 (comment)

@som-snytt
Copy link
Contributor

So this is for java sources only.

@changvvb
Copy link
Contributor Author

changvvb commented Jan 2, 2021

@odersky @som-snytt Though this is for java only, it indeed affects the interoperation with protobuf-java and some sbt plugins like https://github.com/sbt/sbt-protobuf.

@som-snytt
Copy link
Contributor

The linked Scala 2 fix already prompted an issue for Scala 3

#6138

Link to comment in the Scala 2 fix

https://github.com/scala/scala/pull/7671/files#diff-334a019606bce49aa3cb747735d76c2c327c883f1f8f07a0dc65f072243341ebR1440

Showing fix on Scala 2 test case and similar Scala 3 error:

➜  sdk use scala 2.12.10

Using scala version 2.12.10 in this shell.
➜  scalac -d /tmp test/files/pos/java-inherited-type-protobuf/*a
➜  sdk use scala 2.12.2

Using scala version 2.12.2 in this shell.
➜  scalac -d /tmp test/files/pos/java-inherited-type-protobuf/*a
test/files/pos/java-inherited-type-protobuf/Test.java:8: error: GeneratedMessage.this.Builder does not take type parameters
    GeneratedMessage(Builder<?> builder) {
                     ^
one error found
➜  sdk use scala 3.0.0-M3

Using scala version 3.0.0-M3 in this shell.
➜  scalac -d /tmp test/files/pos/java-inherited-type-protobuf/*a
-- [E053] Type Error: test/files/pos/java-inherited-type-protobuf/Test.java:8:21
8 |    GeneratedMessage(Builder<?> builder) {
  |                     ^^^^^^^^^^
  |               GeneratedMessage.this.Builder does not take type parameters

@changvvb
Copy link
Contributor Author

changvvb commented Jan 2, 2021

Yes, this is duplicated with #6138 but seems no plan for the issue.

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.

3 participants