groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jesper Steen Møller <jes...@selskabet.org>
Subject Re: Progress on the Antlr4-based parser
Date Mon, 07 Mar 2016 11:29:15 GMT
Hi Blackdrag

On 7. mar. 2016, at 10.02, Jochen Theodorou <blackdrag@gmx.org> wrote:
> 
> On 07.03.2016 07:48, Jesper Steen Møller wrote:
> [...]
>> 
>> So you can help me with a couple of answers:
>> 
>>  * Is it a goal to close the gap to Java’s more trickier syntax, such
>>    as placement-new and placement constructor calls? From what I can
>>    tell, we’d have to extend the AST too to support that. Has anyone
>>    ever used that except in compiler test cases?
> 
> I had to actually look up what you mean... so you can give type arguments in a constructor
call? I did actually not know this. I would not give this one any priority, unless it is easy
to do… but then I would not really give it an AST implementation yet

It’s certainly not something which is used a lot. Yes, you can declare type parameters for
constructors like you can for methods. This is not supported in Groovy for now - neither is
calling one.

Actually, placement new and placement constructor calls are different from explicit type arguments.
Placement new is used to specify the ‘outer’-instance for inner classes, and . I really
dont think anyone does that in practise - here is an example:

public class A {
	A(String name) {
		this.me = name;
	}
	String me;
	public class B {
		String who() {
			return "I'm a B inside " + me;
		}
	}
	public static class C extends B {
		C(A outer) {
			outer.super(); // This is “placement constructor”, could be fudged in the AST as function
call until late in compilation
		}
		String who() {
			return "I'm a C inheiriting from this guy: " + super.who();
		}
	}
	public static void main(String[] args) {
		A a1 = new A("John");
		A a2 = new A("Paul");
		B b = a1.new B();  // This is "placement new" - may require AST for groovy, certainly grammar
		System.out.println(b.who());
		C c = new C(a2);
		System.out.println(c.who());
	}
}

Just what you always needed, right? I only learned about it from working on the JDT compiler.

Also - I’m also -1 on introducing these pretty much useless Java features — it’s not
“gratuitous incompatibility”, but major complications without any use. I’ll keep a list,
but stop asking…

> 
>>  * ./benchmark/bench/heapsort.groovy uses access modfiers on the
>>    script’s local variables — that’s not really allowed, is it? How
>>    should that work? It can’t get it to work in Groovy 2.4.x
> 
> You mean like "public static final long IM = 139968"? It does not really make a semantic
sense to allow this. For convenient copy&paste this could be allowed... if it poses no
problem, I think it would be nice to have. But it is not really required
> 
But what should it mean? Should it become fields in the Script class, or just be stripped
of access and staticness and introduced as locals in the main() ?

Since it doesn’t work in Groovy now, I don’t understand why it’s in the repo at all…

-Jesper


Mime
View raw message