Skip to content
Permalink
Browse files
8244559: [lworld] Lambda and parameterized ref of an inline type does…
…n't work well
  • Loading branch information
Srikanth Adayapalam committed May 8, 2020
1 parent b2f5a1a commit e586cdbe737261930b0f302312f8881a0e26ae62
Showing 3 changed files with 73 additions and 4 deletions.
@@ -1621,10 +1621,13 @@ public void visitSelect(JCFieldAccess tree) {

public void visitSelectInternal(JCFieldAccess tree) {
if (tree.type.tsym.isStatic() &&
tree.selected.type.isParameterized()) {
tree.selected.type.isParameterized() &&
(tree.name != names.ref || !tree.type.isReferenceProjection())) {
// The enclosing type is not a class, so we are
// looking at a static member type. However, the
// qualifying expression is parameterized.
// Tolerate the pseudo-select V.ref: V<T>.ref will be static if V<T> is and
// should not be confused as selecting a static member of a parameterized type.
log.error(tree.pos(), Errors.CantSelectStaticClassFromParamType);
} else {
// otherwise validate the rest of the expression
@@ -810,9 +810,18 @@ public JCExpression Type(Type t) {
}
default: {
if (t.isReferenceProjection()) {
JCFieldAccess f = (JCFieldAccess) Select(Type(t.valueProjection()), t.tsym);
f.name = names.ref;
tp = f;
// For parameterized types, we want V.ref<A1 ... An> not V<A1 ... An>.ref
JCExpression vp = Type(t.valueProjection());
if (vp.hasTag(Tag.TYPEAPPLY)) {
// vp now is V<A1 ... An>, build V.ref<A1 ... An>
JCFieldAccess f = (JCFieldAccess) Select(((JCTypeApply) vp).clazz, t.tsym);
f.name = names.ref;
tp = TypeApply(f, ((JCTypeApply) vp).arguments);
} else {
JCFieldAccess f = (JCFieldAccess) Select(vp, t.tsym);
f.name = names.ref;
tp = f;
}
} else {
Type outer = t.getEnclosingType();
JCExpression clazz = outer.hasTag(CLASS) && t.tsym.owner.kind == TYP
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 8244559
* @summary Check that javac transforms Types to AST nodes properly.
* @run main ProperTypeApplySelectTest
*/

import java.util.List;

public class ProperTypeApplySelectTest {

static String out = "";

inline static class Foo<V> {
int x;
Foo(int x) { this.x = x; }
}

static void m(Foo foo) {
out += "inline";
}
static void m(Foo.ref foo) {
out += "ref";
}

public static void main(String[] args) {
List<Foo.ref<Integer>> list = List.of(new Foo<Integer>(3));
list.stream().forEach(e -> m(e));
if (!out.equals("ref"))
throw new AssertionError("Unexpected: " + out);
}
}

0 comments on commit e586cdb

Please sign in to comment.