Skip to content

Commit

Permalink
Capture test cases from hohwille
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-herrmann committed May 19, 2024
1 parent c64c3d7 commit 47c55b3
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -509,17 +509,23 @@ static int minorFromRawVersion (String version, String rawVersion) {
}
}
if (version == JavaCore.VERSION_17) {
if ("17-ea".equals(rawVersion)) {
return 0000;
}
if ("17".equals(rawVersion)) {
return 0000;
}
if ("17.0.1".equals(rawVersion)) {
return 0100;
}
if ("17.0.2".equals(rawVersion)) {
return 0200;
switch (rawVersion) {
case "17-ea":
return 0000;
case "17":
return 0000;
case "17.0.1":
return 0100;
case "17.0.2":
return 0200;
case "17.0.3":
return 0300;
case "17.0.4":
return 0400;
case "17.0.5":
return 0500;
case "17.0.6":
return 0600;
}
}
if (version == JavaCore.VERSION_18) {
Expand Down Expand Up @@ -564,6 +570,11 @@ static int minorFromRawVersion (String version, String rawVersion) {
return 0200;
}
}
if (version == JavaCore.VERSION_21) {
switch (rawVersion) {
case "21": return 0;
}
}
if (version == JavaCore.VERSION_22) {
if ("22".equals(rawVersion)) {
return 0000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,174 @@ The method error(List<V>, T) in the type Outer is not applicable for the argumen
----------
""");
}

public void testHohwille_20160104() {
// see https://github.com/m-m-m/util/issues/166#issuecomment-168652351
/* javac:
CombinedInterface.java:9: error: reference to setValue is ambiguous
setValue(Boolean.valueOf(value));
^
both method setValue(Boolean) in TypedInterface and method setValue(V) in GenericInterface match
where V is a type-variable:
V extends Object declared in interface GenericInterface
1 error
*/
runConformTest(
new String[] {
"CombinedInterface.java",
"""
interface GenericInterface<V> {
void setValue(V value);
}
interface TypedInterface {
void setValue(Boolean value);
}
public interface CombinedInterface extends GenericInterface<Boolean>, TypedInterface {
default void set(boolean value) {
setValue(Boolean.valueOf(value));
}
}
"""
});
}

public void testHohwille_20180606() {
/* see https://github.com/m-m-m/util/issues/166#issuecomment-395133804
javac:
GenericTest.java:3: error: type argument ? super B is not within bounds of type-variable B
private final GenericTest<? super A, ? super B> parent;
^
where B,A are type-variables:
B extends A declared in class GenericTest
A extends Object declared in class GenericTest
GenericTest.java:5: error: type argument ? super B is not within bounds of type-variable B
public GenericTest(GenericTest<? super A, ? super B> parent) {
^
where B,A are type-variables:
B extends A declared in class GenericTest
A extends Object declared in class GenericTest
2 errors
*/
runConformTest(
new String[] {
"GenericTest.java",
"""
public class GenericTest<A, B extends A> {
private final GenericTest<? super A, ? super B> parent;
public GenericTest(GenericTest<? super A, ? super B> parent) {
super();
this.parent = parent;
}
}
"""
});
}
public void testHohwille_20231104() {
/* see https://github.com/m-m-m/util/issues/166#issuecomment-1793234294
and https://bugs.openjdk.org/browse/JDK-8319461
My reduction
javac:
PropertyFactoryManager.java:15: error: incompatible types: inference variable P#1 has incompatible bounds
MyPropertyFactory factory = getRequiredFactory(propertyType, valueClass);
^
equality constraints: P#2
upper bounds: WritableProperty<V#1>,ReadableProperty<V#1>
where P#1,V#1,P#2,V#2 are type-variables:
P#1 extends ReadableProperty<V#1> declared in method <V#1,P#1>getRequiredFactory(Class<P#1>,Class<V#1>)
V#1 extends Object declared in method <V#1,P#1>getRequiredFactory(Class<P#1>,Class<V#1>)
P#2 extends ReadableProperty<V#2> declared in method <V#2,P#2>create(Class<P#2>,Class<V#2>)
V#2 extends Object declared in method <V#2,P#2>create(Class<P#2>,Class<V#2>)
PropertyFactoryManager.java:21: error: incompatible types: inference variable P#1 has incompatible bounds
MyPropertyFactory factory = getRequiredFactory(propertyType, typeInfo.getValueClass());
^
equality constraints: P#2
upper bounds: WritableProperty<V#1>,ReadableProperty<V#1>
where P#1,V#1,P#2,V#2 are type-variables:
P#1 extends ReadableProperty<V#1> declared in method <V#1,P#1>getRequiredFactory(Class<P#1>,Class<V#1>)
V#1 extends Object declared in method <V#1,P#1>getRequiredFactory(Class<P#1>,Class<V#1>)
P#2 extends ReadableProperty<V#2> declared in method <V#2,P#2>create(Class<P#2>,PropertyTypeInfo<V#2>)
V#2 extends Object declared in method <V#2,P#2>create(Class<P#2>,PropertyTypeInfo<V#2>)
2 errors
*/
runConformTest(
new String[] {
"PropertyFactoryManager.java",
"""
interface WritableObservableValue<V> { }
interface ReadableProperty<V> { }
interface WritableProperty<V> extends WritableObservableValue<V>, ReadableProperty<V> { }
interface PropertyTypeInfo<V> {
Class<V> getValueClass();
}
interface MyPropertyFactory<V, P extends WritableProperty<V>> {
<P2 extends ReadableProperty<V>> P2 create(PropertyTypeInfo<V> typeInfo);
}
public interface PropertyFactoryManager {
@SuppressWarnings({ "rawtypes" })
default <V, P extends ReadableProperty<V>> MyPropertyFactory create(Class<P> propertyType, Class<V> valueClass) {
// https://github.com/m-m-m/util/issues/166
MyPropertyFactory factory = getRequiredFactory(propertyType, valueClass);
return factory;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
default <V, P extends ReadableProperty<V>> P create(Class<P> propertyType, PropertyTypeInfo<V> typeInfo) {
// https://github.com/m-m-m/util/issues/166
MyPropertyFactory factory = getRequiredFactory(propertyType, typeInfo.getValueClass());
return (P) factory.create(typeInfo);
}
default <V, P extends ReadableProperty<V>> MyPropertyFactory<V, ? extends P> getRequiredFactory(
Class<P> propertyType, Class<V> valueType) {
return null;
}
}
"""
});
}
public void testJDK8319461() {
/* Hohwille's reduction of the above
javac (the warning is irrelevant, could be easily avoided:
JDK8319461.java:3: warning: [rawtypes] found raw type: Factory
Factory factory = getFactory(propertyType, valueClass);
^
missing type arguments for generic class Factory<V,P>
where V,P are type-variables:
V extends Object declared in interface Factory
P extends WritableProperty<V> declared in interface Factory
JDK8319461.java:3: error: incompatible types: inference variable P#1 has incompatible bounds
Factory factory = getFactory(propertyType, valueClass);
^
equality constraints: P#2
upper bounds: WritableProperty<V#1>,ReadableProperty<V#1>
where P#1,V#1,P#2,V#2 are type-variables:
P#1 extends ReadableProperty<V#1> declared in method <V#1,P#1>getFactory(Class<P#1>,Class<V#1>)
V#1 extends Object declared in method <V#1,P#1>getFactory(Class<P#1>,Class<V#1>)
P#2 extends ReadableProperty<V#2> declared in method <V#2,P#2>create(Class<P#2>,Class<V#2>,String)
V#2 extends Object declared in method <V#2,P#2>create(Class<P#2>,Class<V#2>,String)
1 error
1 warning
*/
runConformTest(
new String[] {
"JDK8319461.java",
"""
public class JDK8319461 {
public <V, P extends ReadableProperty<V>> P create(Class<P> propertyType, Class<V> valueClass, String name) {
Factory factory = getFactory(propertyType, valueClass);
return null;
}
public <V, P extends ReadableProperty<V>> Factory<V, ? extends P> getFactory(Class<P> propertyType, Class<V> valueType) {
Factory<V, ? extends P> factory = null;
return factory;
}
public interface ReadableProperty<V> { }
public interface WritableProperty<V> extends ReadableProperty<V> { }
public interface Factory<V, P extends WritableProperty<V>> { }
}
"""
});
}
}

0 comments on commit 47c55b3

Please sign in to comment.