Question about error message for primitive type arguments[Re: The compiler rejects <void>this/super().]
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Mar 8 11:30:22 PST 2012
Yep - this is deliberate - in the sense that I got the constructor call
working in the same way method call code does - but I still need to plug
some holes in both. I.e. this code used to produce a diagnostic very
similar to the one you described:
class Main {
public <E> void m(Object o) {}
public Main()
{
this.<int>m(null); // Illegal
}
}
This was before/after the fix. So, now the implementation is consistent
in terms of constructor vs. method calls. Now we have to add one more
extra check to reject primitive types (other than void) as explicit
type-parameters. More specifically, we also need to reject 'void' in
case the corresponding formal parameter is not a thrown type-parameter.
Maurizio
On 08/03/12 18:52, bitter_fox wrote:
> Thank you for the fix.
>
> I have a question about the error message for primitive type arguments.
>
> Old javac says "unexpected type" for this.<int>m(), <int>this/super()
> and Clazz<int>.
> However, today's implementation says it only for Clazz<int>.
> It says another massage for this.<int>m() and <int>this/super():
>
> Main.java:9: error: no suitable constructor found for Main(<null>)
> <int>this(null);
> ^
> constructor Main.Main() is not applicable
> (actual and formal argument lists differ in length)
> constructor Main.<T>Main(Object) is not applicable
> (explicit type argument int does not conform to declared
> bound(s) Object)
> where T is a type-variable:
> T extends Object declared in constructor <T>Main(Object)
> Main.java:10: error: method m in class Main<T> cannot be applied to
> given types;
>
> this.<int>m();
> ^
> required: no arguments
> found: no arguments
> reason: explicit type argument int does not conform to declared
> bound(s) Objec
> t
> where T is a type-variable:
> T extends Object declared in class Main
>
> Was this change intended?
>
> Regards,
> bitter_fox
>
> 2012/3/8 Maurizio Cimadamore <maurizio.cimadamore at oracle.com
> <mailto:maurizio.cimadamore at oracle.com>>
>
> On 08/03/12 09:46, bitter_fox wrote:
>
> class Main
> {
> public<throws E> Main(Object o) {}
>
> public Main()
> {
> <void>this(null); // Illegal
> }
> }
>
> Nicely spotted - thanks!
>
> Maurizio
>
>
More information about the lambda-dev
mailing list