Summary
Javac's implementation of method resolution needs to be synced with the spec. There are some minor discrepancies that need to be resolved.
Problem
Javac is not in sync with section §15.12.3 of the JLS 16 specification. In particular, for invocations in static context, javac too early checks whether the method is static, and when it determines it is not static and cannot be called, proceeds to a further phase in method lookup, even though it should report a compile-time error.
Solution
Synchronize javac with section §15.12.3 of the JLS 16 specification.
Specification
Of interest for this CSR is section §15.12.3 of the JLS 16 specification, titled: "Compile-Time Step 3: Is the Chosen Method Appropriate?" in particular where it reads:
In addition, whether the compile-time declaration is appropriate may depend on the
form of the method invocation expression before the left parenthesis, as follows:
• If the form is MethodName - that is, just an Identifier - and the compile-time
declaration is an instance method, then:
– It is a compile-time error if the method invocation occurs in a static context
(§8.1.3).
- csr of
-
JDK-8238213 Method resolution should stop on static error
-
- Closed
-
- relates to
-
JDK-8289277 A static method with varargs is not correctly recognized from a static context.
-
- Closed
-