Record component type can be an inner class of a record

Dan Smith daniel.smith at oracle.com
Mon Apr 20 22:32:34 UTC 2020



> On Apr 19, 2020, at 10:40 AM, forax at univ-mlv.fr wrote:
> 
> Hi Dan,
> 
> ----- Mail original -----
>> De: "daniel smith" <daniel.smith at oracle.com>
>> À: "Remi Forax" <forax at univ-mlv.fr>
>> Cc: "Gavin Bierman" <gavin.bierman at oracle.com>, "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
>> Envoyé: Lundi 13 Avril 2020 21:13:51
>> Objet: Re: Record component type can be an inner class of a record
> 
>>> On Apr 13, 2020, at 11:08 AM, forax at univ-mlv.fr wrote:
>>> 
>>> I believe you're right, the following code should not compile, apart if you want
>>> to write puzzler for a living :)
>>> 
>>> class A { int y; }
>>> 
>>> record B(A a) implements I {
>>>  public static void main(String[] args) {
>>>    System.out.println(new B(null).a().x);
>>>  }
>>> }
>>> 
>>> interface I {
>>>  class A { int x; }
>>> }
>> 
>> You're proposing a novel error check, which I'm not sure is a good idea.
> 
> I think you mis-read it.
> It's an example that shows that depending if the record component type is resolve as part of outside of the record or inside the record, not the same A is picked.
> The A at top level declare a field "y" while the A inside I declare a field "x", that why it doesn't compile.
> So it's not a new error check.

My point: there are no references to 'A' inside the body. The only reference to 'A' in this program unambiguously refers to the top-level A.

You seem to be assuming that there will be resolution problems involved in checking the implicit members. And my response is that it's not our job to perform name resolution for implicit members—they are defined more abstractly than that. Specifically, the return type of the 'a' method is the type referenced by the type name 'A' appearing after 'record B(' in the program, as it is resolved *at that location*.


More information about the amber-spec-experts mailing list