hg: valhalla/valhalla/langtools: Add initial conditional method support:

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Wed Oct 22 23:02:30 UTC 2014


Hi Ali,
you are right - this should not compile. My intention was to verify that 
i.e. 'new Foo<int>' worked, but I agree that it is not sound to allow 
instantiation _for any Z_.
On top of my head, I believe the issue lies in the fact that I shared 
the same compile-time check for two purposes:

1) verifying that you can actually call a RefOnly method on a receiver T 
(to check method calls)
2) verifying that a RefOnly method is a member of a given type (for 
well-formedness check - as in your example)

While the check is correct for the first use case, in hindsight, it 
isn't strict enough for the second; note that, as far as (1) is 
concerned, in your example m() would _not_ be a callable method for a 
receiver Foo<any T> (and that's correct - as Foo<any T> can be 
parameterized with non-reference types); unfortunately, as the logic is 
reused, this means that javac would also _not_ consider m() to be a 
member of Foo<any T> - which is why the instantiation goes without 
errors. Obviously, the two use cases need slightly different logic: in 
one case you need to prove that at least one parameterization is 
non-reference to ban a method call; in the other case you have to prove 
that all instantiations are non-reference to exclude the method from the 
list of members. We can still share the check - but the routine has to 
be more clever than it is now :-)

Thanks for the prompt report.

Maurizio

On 22/10/14 21:45, Ali Ebrahimi wrote:
> Hi Maurizio,
> One question:
> in test method test1 of class TestRefOnly02:
>
> class TestRefOnly02 {
>      static abstract class Foo<any T> {
>          abstract __RefOnly void m();
>      }
>
>      <any Z> void test1() {
>          new Foo<Z>() { };  <======
>      }
>
> ...
> }
> This line should not produce compile  error: 
> compiler.err.does.not.override.abstract:
> new Foo<Z>() { };
>
> Sinceany type var "Z" canalsobe Ref type.
> Am I missing some thing here?
> Is this correct?
>      <any Z> void test1() {
>          new Foo<Z>() {
>           __RefOnly void m(){  }
>          };
>      }
Yes - I think that should be correct.

Maurizio
> Best Regards,
> Ali Ebrahimi
>
> On Wed, Oct 22, 2014 at 10:41 PM, <maurizio.cimadamore at oracle.com 
> <mailto:maurizio.cimadamore at oracle.com>> wrote:
>
>     Changeset: 3ffc6541ddba
>     Author:    mcimadamore
>     Date:      2014-10-22 20:10 +0100
>     URL:
>     http://hg.openjdk.java.net/valhalla/valhalla/langtools/rev/3ffc6541ddba
>
>     Add initial conditional method support:
>     * __RefOnly keyword can be used to tag methods that should only be
>     available on 'erased' receivers
>     * Better encapsulation for TypeVariable.bound
>     * Add support for context-dependent semantics for 'any' type-variables
>
>     ! src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java
>     ! src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java
>     ! src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java
>     ! src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
>     ! src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
>     ! src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java
>     ! src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java
>     !
>     src/jdk.compiler/share/classes/com/sun/tools/javac/comp/SpecializeTypes.java
>     !
>     src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java
>     !
>     src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
>     ! src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java
>     !
>     src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java
>     !
>     src/jdk.compiler/share/classes/com/sun/tools/javac/parser/Tokens.java
>     !
>     src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties
>     !
>     src/jdk.compiler/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java
>     + test/tools/javac/diags/examples/IllegalRefOnlyCall.java
>     ! test/tools/javac/lib/DPrinter.java
>     + test/tools/javac/valhalla/typespec/TestRefOnly01.java
>     + test/tools/javac/valhalla/typespec/TestRefOnly01.out
>     + test/tools/javac/valhalla/typespec/TestRefOnly02.java
>     + test/tools/javac/valhalla/typespec/TestRefOnly02.out
>     + test/tools/javac/valhalla/typespec/TestRefOnly03.java
>     + test/tools/javac/valhalla/typespec/TestRefOnly03.out
>     + test/tools/javac/valhalla/typespec/TestRefOnly04.java
>     + test/tools/javac/valhalla/typespec/TestRefOnly05.java
>     + test/tools/javac/valhalla/typespec/TestRefOnly06.java
>     + test/tools/javac/valhalla/typespec/items/tests/TestRefOnly.java
>
>



More information about the valhalla-dev mailing list