permit with a class which is not a subtype is allowed

forax at univ-mlv.fr forax at univ-mlv.fr
Tue Sep 3 13:31:35 UTC 2019


----- Mail original -----
> De: "Maurizio Cimadamore" <maurizio.cimadamore at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>, "amber-dev" <amber-dev at openjdk.java.net>
> Envoyé: Mardi 3 Septembre 2019 15:19:33
> Objet: Re: permit with a class which is not a subtype is allowed

> I think there might be a range of options here - error is one, lint
> warning (e.g. redundant permits) is another.

I don't see the point of being able to specify a type which is not a subtype given that it will never checked by the VM
the VM only check when you load a class that if the parent as a an attribute PermittedSubtypes then the class is among the permitted subtypes.

In my opinion, the attribute "PermittedSubtypes" should only store direct subtypes and it should be enforced by the compiler.

otherwise you can write some fun stuff like
  sealed interface I permits J { }
  sealed interface J permits I { }

note that I and J are not related in term of hierarchy.

> 
> But, nevertheless you raise a valid point.
> 
> Maurizio

Rémi

> 
> On 03/09/2019 14:03, Remi Forax wrote:
>> The compiler allows to permit a class which is not a subtype.
>>
>> public class AncestorPermitExample {
>>    sealed interface I permits A {
>>    	
>>    }
>>    final static class A {
>>    	
>>    }
>> }
>>
>> The VM too but it's not a bug for the VM (i believe).
>>
> > Rémi


More information about the amber-dev mailing list