Bug in JLS specification for restriction on where a return statement is allowed.
Alex Buckley
Alex.Buckley at Sun.COM
Fri Dec 4 10:33:36 PST 2009
Ted,
Yes, that can be argued. In practice, there is almost no chance that the
JLS text (unchanged since JLS1) has confused compiler writers or
programmers. The C# 3.0 spec (8.9.4) has very similar wording.
On the other hand, the Scala 2.7 spec (6.20) does a better job. Absolute
precision *is* a goal for a spec. So is making conservative changes to a
widely-distributed document; my proposal in 6906550 minimizes rewording
but is arguably less direct than Scala's wording. (Then again, the Scala
spec doesn't have to worry about constructors.)
Of course, as a specification issue, this is off-topic for compiler-dev.
Alex
Ted Neward wrote:
> Can’t it be argued that the “return” doesn’t appear within the instance
> or static initializer, but within a construct which happens to be inside
> an initializer? (Meaning the text is, at best, ambiguous?)
>
>
>
> Not trying to nit-pick, just trying to understand how deeply detailed
> the specification needs to be, to be honest.
>
>
>
> Ted Neward
>
> Java, .NET, XML Services
>
> Consulting, Teaching, Speaking, Writing
>
> http://www.tedneward.com
>
>
>
>
>
> *From:* compiler-dev-bounces at openjdk.java.net
> [mailto:compiler-dev-bounces at openjdk.java.net] *On Behalf Of *Neal Gafter
> *Sent:* Wednesday, December 02, 2009 9:24 AM
> *To:* Alexander Buckley
> *Cc:* OpenJDK
> *Subject:* Bug in JLS specification for restriction on where a return
> statement is allowed.
>
>
>
> Alex-
>
> JLS 14.17 says
>
> A compile-time error occurs if a |return| statement appears within an
> instance initializer or a static initializer (§8.7)
> <http://java.sun.com/docs/books/jls/third_edition/html/classes.html#39245>.
>
>
> However, javac allows a return statement within an instance or static
> initializer if there is an intervening nested inner class with a method.
>
> *static { // static initializer*
> * class X {*
> * void foo() {*
> * return; // yet return allowed within it*
> * }*
> * }*
> *}*
>
>
> I believe this is a bug in the specification.
>
> Cheers,
> Neal
>
More information about the compiler-dev
mailing list