permit with a class which is not a subtype is allowed

Brian Goetz brian.goetz at oracle.com
Tue Sep 3 16:13:58 UTC 2019


> And you have the second effect which is, if the permit clause raise a warning when the class doesn't exist, it logically also means that the case clause of a switch on type also raises a warning when the class doesn't exist.
>

This is true, but remember such things can happen in different files.  
The real question is whether the naming of a type in a permits clause is 
a _use_ of that type.  (Clearly, naming a type in a case clause is a 
use.)  So while it would be impossible for a switch to proceed without 
being able to find all the types it names, the same is not necessarily 
true for the declaration.

I get what you're saying: "this will catch more errors, and I don't see 
the downside, so its good".  And that may in the end be how we want to 
do it.

The reality is that the compiler doesn't _need_ to go and find all the 
named classes when we compile the declaration.  And to the extent that 
this might make life more difficult for users that have weird build 
procedures, where the subtype can't be found at compile time, doing so 
_just for the purpose of error checking_ is a cost, which needs to be 
set off against the benefit.

As I said, my current inclination is to warn here, but I could imagine 
backing off in either direction.


More information about the amber-spec-experts mailing list