Skip to content

Commit 8c37909

Browse files
author
Vicente Romero
committedSep 3, 2021
8273234: extended 'for' with expression of type tvar causes the compiler to crash
Reviewed-by: jlahoda
1 parent 28ba78e commit 8c37909

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed
 

‎src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ public void visitForeachLoop(JCEnhancedForLoop tree) {
15461546
// Check the return type of the method iterator().
15471547
// This is the bare minimum we need to verify to make sure code generation doesn't crash.
15481548
Symbol iterSymbol = rs.resolveInternalMethod(tree.pos(),
1549-
loopEnv, exprType, names.iterator, List.nil(), List.nil());
1549+
loopEnv, types.skipTypeVars(exprType, false), names.iterator, List.nil(), List.nil());
15501550
if (types.asSuper(iterSymbol.type.getReturnType(), syms.iteratorType.tsym) == null) {
15511551
log.error(tree.pos(),
15521552
Errors.ForeachNotApplicableToType(exprType, Fragments.TypeReqArrayOrIterable));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8273234
27+
* @summary extended 'for' with expression of type tvar causes the compiler to crash
28+
* @compile ExprTypeIsTypeVariableTest.java
29+
*/
30+
31+
import java.util.*;
32+
33+
class ExprTypeIsTypeVariableTest {
34+
abstract class A {}
35+
36+
abstract class ACD<E> implements Iterable<E> {
37+
public Iterator<E> iterator() {
38+
return null;
39+
}
40+
}
41+
42+
abstract class ALD<E> extends ACD<E> implements List<E> {}
43+
44+
abstract class ASP<NT extends A> extends ALD<A> {
45+
<P extends ASP<NT>> void foo(P prod) {
46+
for (A sym : prod) {}
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)