RFR: 8282823: javac should constrain more uses of preview APIs [v2]
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Tue Mar 15 10:41:47 UTC 2022
On Mon, 14 Mar 2022 20:19:16 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
>> Consider a class or interface with a method marked as preview. Subclassing the class or implementing the interface by itself should not cause a preview error/warning (as that would be problematic for Loom), but overriding the method should produce a preview error/warning.
>>
>> This patch adds the error/warning in case a preview method is overridden.
>
> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
>
> Only produce preview warnings for immediate overriders of preview methods.
Logic looks good. Note that `membersClosure` is memory hungry - although here you are only (correctly) only calling it when there is some preview method around, so I think that's acceptable.
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java line 1912:
> 1910: if (m.owner != origin ||
> 1911: //performance - only do the expensive checks when the overridden method is a Preview API:
> 1912: (other.flags() & PREVIEW_API) == 0) {
indentation seems off here - e.g. I'd expect double "tab" in the second line of the `if` condition?
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java line 1918:
> 1916: for (Symbol s : types.membersClosure(origin.type, false).getSymbolsByName(m.name)) {
> 1917: if (m != s && m.overrides(s, origin, types, false)) {
> 1918: //only check if the preview only if "m" immediatelly overrides "other"
This comments seems to be off
-------------
Marked as reviewed by mcimadamore (Reviewer).
PR: https://git.openjdk.java.net/jdk/pull/7774
More information about the compiler-dev
mailing list