Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit110fa48

Browse files
committed
Skip over JEP 445 compact compilation units
Compact compilation units are not referencable, so we can skip overthem.
1 parent3f09bff commit110fa48

File tree

9 files changed

+57
-6
lines changed

9 files changed

+57
-6
lines changed

‎src/compiler/scala/tools/nsc/javac/JavaParsers.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,14 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
10921092
/** CompilationUnit ::= [[Annotation] package QualId semi] {Import} {TypeDecl} //TopStatSeq
10931093
*/
10941094
defcompilationUnit():Tree= {
1095+
varcompact=false
1096+
deftypeDeclOrCompact(mods:Modifiers):List[Tree]= in.tokenmatch {
1097+
caseENUM|INTERFACE|AT|CLASS|RECORD=> typeDecl(mods)
1098+
case _=>
1099+
valts= termDecl(mods,CLASS)
1100+
if (ts.nonEmpty) compact=true
1101+
Nil
1102+
}
10951103
valbuf=ListBuffer.empty[Tree]
10961104
varpos= in.currentPos
10971105
valleadingAnnots=if (in.token==AT) annotations()elseNil
@@ -1107,7 +1115,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
11071115
}
11081116
else {
11091117
if (!leadingAnnots.isEmpty)
1110-
buf++=typeDecl(modifiers(inInterface=false, annots0= leadingAnnots))
1118+
buf++=typeDeclOrCompact(modifiers(inInterface=false, annots0= leadingAnnots))
11111119
Ident(nme.EMPTY_PACKAGE_NAME)
11121120
}
11131121
thisPackageName= gen.convertToTypeName(pkg)match {
@@ -1120,10 +1128,11 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
11201128
while (in.token!=EOF&& in.token!=RBRACE) {
11211129
while (in.token==SEMI) in.nextToken()
11221130
if (in.token!=EOF)
1123-
buf++=typeDecl(modifiers(inInterface=false))
1131+
buf++=typeDeclOrCompact(modifiers(inInterface=false))
11241132
}
11251133
accept(EOF)
1126-
atPos(pos) {
1134+
if (compact)EmptyTree
1135+
else atPos(pos) {
11271136
makePackaging(pkg, buf.toList)
11281137
}
11291138
}

‎test/files/neg/i20026.check

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
JTest.java:3: error: illegal start of type declaration
1+
JTest.java:3: error: illegal start of type
22
import java.util.*;
3-
^
4-
1 error
3+
^
4+
JTest.java:3: error: identifier expected but `;` found.
5+
import java.util.*;
6+
^
7+
2 errors

‎test/files/neg/t12878.check

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Test.scala:3: error: not found: type H
2+
new H()
3+
^
4+
Test.scala:4: error: not found: value T
5+
new T.H()
6+
^
7+
2 errors

‎test/files/neg/t12878/T.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//> using jvm 21+
2+
//> using javacOpt --enable-preview --release 21
3+
4+
intk =0;
5+
// This should work as compact units have an implicit `import module java.base`, but that doesn't seem to be the case with Java 21 preview
6+
// File f = null;
7+
java.io.Filef =null;
8+
java.io.Fileg =f;
9+
@Deprecatedvoidmain() {return; }
10+
publicclassH { }
11+
publicstaticintk() {return1; }

‎test/files/neg/t12878/Test.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
classTest {
2+
newU
3+
newH()
4+
newT.H()
5+
}

‎test/files/neg/t12878/U.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
publicclassU { }

‎test/files/pos/t12878/T.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//> using jvm 21+
2+
//> using javacOpt --enable-preview --release 21
3+
4+
intk =0;
5+
// This should work as compact units have an implicit `import module java.base`, but that doesn't seem to be the case with Java 21 preview
6+
// File f = null;
7+
java.io.Filef =null;
8+
java.io.Fileg =f;
9+
@Deprecatedvoidmain() {return; }
10+
publicclassH { }
11+
publicstaticintk() {return1; }

‎test/files/pos/t12878/Test.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
classTest {
2+
newU
3+
}

‎test/files/pos/t12878/U.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
publicclassU { }

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp