Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8268474

Method resolution should stop on static error

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 17
    • tools
    • None
    • behavioral
    • minimal
    • This change can provoke that some programs that shouldn't compile but do, will stop compiling. But after running a corpus test we haven't find any affected source in the corpus
    • Other
    • Implementation

      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).

            vromero Vicente Arturo Romero Zaldivar
            webbuggrp Webbug Group
            Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: