D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11795 - DMD allows nested new operator syntax together with anonymous classes
Summary: DMD allows nested new operator syntax together with anonymous classes
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-21 16:18 UTC by Bruno Medeiros
Modified: 2020-03-21 03:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Bruno Medeiros 2013-12-21 16:18:17 UTC
It seems DMD syntactically allows the new operator nested class instantiation syntax together with the anonymous class syntax, like this:

  auto outer = new Outer();
  outer.new class Inner { };

This syntax never makes sense, because an anonymous class instantiation always defines an outer context by itself (by means of the surrounding scope), so it cannot have another outer scope (ie, the outer class). Using this syntax will always result in a semantic error, or some compiler internal error. For example the following code compiles without semantic errors, but the linker fails:

class Outer {
	int foo;
	auto x = new Outer().new class Inner {};

	class Inner {
	}
}

void main() {
}
Comment 1 basile-z 2019-02-13 01:37:32 UTC
It's a front end error nowadays.

Error: class `temp_7FCDE39084D0.Outer` no size because of forward reference

Although the error message might be better.