"jigsaw-dev" <jigsaw-dev-boun...@openjdk.java.net> wrote on 21/11/2018 01:56:42 AM:
> From: Alex Buckley <alex.buck...@oracle.com > > On 11/20/2018 10:54 AM, Alex Buckley wrote: > > From the above, it's hard to understand for which file an error is > > reported by Eclipse. In any case, as Jon indicated, if the file D.java > > is empty, then there is no stream of tokens matching the JLS 7.3 > > production `CompilationUnit` and thus there is no compilation unit to > > discuss. Sorry for not being clear. C.java is fine and it's D.java that is being reported by the Eclipse compiler. > Jon points out that `OrdinaryCompilationUnit` will match an empty stream > of tokens (I dislike the syntax-driven optionality here, but it's > longstanding) so the file D.java could be regarded as a compilation unit > with no package declaration, no import declarations, and no type > declarations. > > Per JLS 7.4.2, such a compilation unit is in an unnamed package, and > must be associated with an unnamed module. (The "must" somewhat > conflicts with the "may" in > https://urldefense.proofpoint.com/v2/url? > u=https-3A__docs.oracle.com_javase_specs_jls_se11_html_jls-2D7.html-23jls-2D7. > 3-2D310&d=DwIC-g&c=jf_iaSHvJObTbx- > siA1ZOg&r=LuMqcl3PU0i2olgTvkVvFthzqyc_3wGfGooplpAvFsc&m=0-yB- > s6iIk8sBeNaaAkAlma7IqqfciaUiZ0EyShDTLk&s=aRQM4fwhr3kUvHE9tcUkUscWSmnPllgXg08OI8VA80c&e= > ) > > I would prefer 7.4.2 to say only that a compilation unit with no package > declarations _and at least one type declaration_ is in an unnamed > package (and must be associated with an unnamed module; 7.3 should > enumerate that possibility). A compilation unit with no package > declarations _and no type declarations_ would be deemed unobservable by > 7.3, and all these questions about what to do with empty files would > disappear. That would be perfect and make things unambiguous. But for now, the paragraph above is good enough for me. > What do compiler engineers think? > > Alex >