RFR: 8325324: Implement Implicitly Declared Classes and Instance Main Methods (Third Preview) [v3]
Jan Lahoda
jlahoda at openjdk.org
Mon May 6 14:09:54 UTC 2024
On Fri, 3 May 2024 10:25:43 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> It was meant to be permanent, even though now transiently it is more important. Long term, it is much less important for the implicit imports in implicit classes. The String Templates code was trying to detect if the `StringTemplate` class exists and avoid the implicit import if it didn't. That didn't work very well, and was causing issues in some corner cases. So, I used the speculative attribution, and used it for implicitly declared classes as well.
>>
>> The reason why I used the speculative attribution is that it does not have side-effects - i.e. if the class does not exist, and the user types `java.io.IO` explicitly, there will still be an error. With `synthetizeEmptyInterfaceIfMissing`, there will be no error reported, even for explicit uses of the type, I believe.
>
> Maybe we should also set `SYNTHETIC` in `synthetizeEmptyInterfaceIfMissing` ? That method was mostly added so that a "real" type was available to javac. That said, if you didn't want to mess with that I understand, but the general approach seem to remain valid - e.g. in principle we should be able to wrap the `IO`'s symbol completer, so that if a completion error occurs, the error is swallowed (and then we know the type doesn't exist). In other words, a deferred attribution seems an heavy way to see if a type is there?
I still think the `synthetizeEmptyInterfaceIfMissing` is a bit too optimistic - that makes the type "available" to javac even if does not exist, and that is probably not correct in this case. (It would mean one could write `java.io.IO io;`, and not get an error even if type didn't exist.)
But, I admit the speculative attribution was probably a bit too pessimistic. I've changed the code to do attribution, and check the result. Does this look better?
Thanks!
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18633#discussion_r1591067865
More information about the compiler-dev
mailing list