Skip to content

Java raw type selection rules not enforced #19628

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
bishabosha opened this issue Feb 6, 2024 · 2 comments
Closed

Java raw type selection rules not enforced #19628

bishabosha opened this issue Feb 6, 2024 · 2 comments

Comments

@bishabosha
Copy link
Member

bishabosha commented Feb 6, 2024

When compiling java source code, rules about Raw types are not enforced.

note that in any real project, the javac compiler will also run and check these rules so this is not super high priority

Compiler version

3.4.0-RC3

Minimized code

// RawTypes.java

package lib;

public class RawTypes {

  public class C<T> {
    public class D<U> {}
  }

  public static void m_Raw_Raw(C.D d) {}
  public static void m_Raw_Gen(C.D<Object> d) {} // should be error
  public static void m_Gen_Raw(C<Object>.D d) {} // should be error

}

Output

compiles ok

Expectation

javac compiler gives these errors:

RawTypes.java:10: error: improperly formed type, type arguments given on a raw type
  public static void m_Raw_Gen(C.D<Object> d) {} // should be error
                                  ^
RawTypes.java:11: error: improperly formed type, some parameters are missing
  public static void m_Gen_Raw(C<Object>.D d) {} // should be error
                                        ^
2 errors

JLS 4.8 states these rules

It is a compile-time error to pass type arguments to a non-static member class or interface of a raw type that is not inherited from its superclasses or superinterfaces.

^ this invalidates C.D<Object> as a type, because D is not static, and C is a raw type.

It is a compile-time error to attempt to use a member class or interface of a parameterized type as a raw type.

^ this invalidates C<Object>.D as a type, because D is not allowed to be a raw type when C is parameterized.

Notes

C.D is ok because they are all raw types.

@bishabosha
Copy link
Member Author

I have been informed that we only care about correctly type checking known-valid Java code, anything else is up to the compiler

@bishabosha
Copy link
Member Author

I will close this in favor of adding more examples to #19619

@bishabosha bishabosha closed this as not planned Won't fix, can't repro, duplicate, stale Feb 7, 2024
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

1 participant