Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8026369: javac potentially ambiguous overload warning needs an improv…
…ed scheme

Reviewed-by: vromero
  • Loading branch information
archiecobbs authored and Vicente Romero committed Feb 28, 2023
1 parent 14a014d commit 1e3c9fd
Show file tree
Hide file tree
Showing 16 changed files with 362 additions and 80 deletions.
Expand Up @@ -63,6 +63,7 @@
* <p>This implementation does not check for overflow of the count or the sum.
* @since 1.8
*/
@SuppressWarnings("overloads")
public class LongSummaryStatistics implements LongConsumer, IntConsumer {
private long count;
private long sum;
Expand Down
3 changes: 3 additions & 0 deletions src/java.base/share/classes/java/util/PrimitiveIterator.java
Expand Up @@ -91,6 +91,7 @@ public interface PrimitiveIterator<T, T_CONS> extends Iterator<T> {
* An Iterator specialized for {@code int} values.
* @since 1.8
*/
@SuppressWarnings("overloads")
public static interface OfInt extends PrimitiveIterator<Integer, IntConsumer> {

/**
Expand Down Expand Up @@ -158,6 +159,7 @@ default void forEachRemaining(Consumer<? super Integer> action) {
* An Iterator specialized for {@code long} values.
* @since 1.8
*/
@SuppressWarnings("overloads")
public static interface OfLong extends PrimitiveIterator<Long, LongConsumer> {

/**
Expand Down Expand Up @@ -224,6 +226,7 @@ default void forEachRemaining(Consumer<? super Long> action) {
* An Iterator specialized for {@code double} values.
* @since 1.8
*/
@SuppressWarnings("overloads")
public static interface OfDouble extends PrimitiveIterator<Double, DoubleConsumer> {

/**
Expand Down
3 changes: 3 additions & 0 deletions src/java.base/share/classes/java/util/Spliterator.java
Expand Up @@ -659,6 +659,7 @@ default void forEachRemaining(T_CONS action) {
* A Spliterator specialized for {@code int} values.
* @since 1.8
*/
@SuppressWarnings("overloads")
public interface OfInt extends OfPrimitive<Integer, IntConsumer, OfInt> {

@Override
Expand Down Expand Up @@ -723,6 +724,7 @@ default void forEachRemaining(Consumer<? super Integer> action) {
* A Spliterator specialized for {@code long} values.
* @since 1.8
*/
@SuppressWarnings("overloads")
public interface OfLong extends OfPrimitive<Long, LongConsumer, OfLong> {

@Override
Expand Down Expand Up @@ -787,6 +789,7 @@ default void forEachRemaining(Consumer<? super Long> action) {
* A Spliterator specialized for {@code double} values.
* @since 1.8
*/
@SuppressWarnings("overloads")
public interface OfDouble extends OfPrimitive<Double, DoubleConsumer, OfDouble> {

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/java.base/share/classes/java/util/Spliterators.java
Expand Up @@ -908,18 +908,21 @@ private static final class OfRef<T>
OfRef() { }
}

@SuppressWarnings("overloads")
private static final class OfInt
extends EmptySpliterator<Integer, Spliterator.OfInt, IntConsumer>
implements Spliterator.OfInt {
OfInt() { }
}

@SuppressWarnings("overloads")
private static final class OfLong
extends EmptySpliterator<Long, Spliterator.OfLong, LongConsumer>
implements Spliterator.OfLong {
OfLong() { }
}

@SuppressWarnings("overloads")
private static final class OfDouble
extends EmptySpliterator<Double, Spliterator.OfDouble, DoubleConsumer>
implements Spliterator.OfDouble {
Expand Down
3 changes: 3 additions & 0 deletions src/java.base/share/classes/java/util/stream/Node.java
Expand Up @@ -314,6 +314,7 @@ default T[] asArray(IntFunction<T[]> generator) {
/**
* Specialized {@code Node} for int elements
*/
@SuppressWarnings("overloads")
interface OfInt extends OfPrimitive<Integer, IntConsumer, int[], Spliterator.OfInt, OfInt> {

/**
Expand Down Expand Up @@ -391,6 +392,7 @@ default StreamShape getShape() {
/**
* Specialized {@code Node} for long elements
*/
@SuppressWarnings("overloads")
interface OfLong extends OfPrimitive<Long, LongConsumer, long[], Spliterator.OfLong, OfLong> {

/**
Expand Down Expand Up @@ -468,6 +470,7 @@ default StreamShape getShape() {
/**
* Specialized {@code Node} for double elements
*/
@SuppressWarnings("overloads")
interface OfDouble extends OfPrimitive<Double, DoubleConsumer, double[], Spliterator.OfDouble, OfDouble> {

/**
Expand Down
9 changes: 9 additions & 0 deletions src/java.base/share/classes/java/util/stream/Nodes.java
Expand Up @@ -582,6 +582,7 @@ public Spliterator<T> spliterator() {
}
}

@SuppressWarnings("overloads")
private static final class OfInt
extends EmptyNode<Integer, int[], IntConsumer>
implements Node.OfInt {
Expand All @@ -599,6 +600,7 @@ public int[] asPrimitiveArray() {
}
}

@SuppressWarnings("overloads")
private static final class OfLong
extends EmptyNode<Long, long[], LongConsumer>
implements Node.OfLong {
Expand All @@ -616,6 +618,7 @@ public long[] asPrimitiveArray() {
}
}

@SuppressWarnings("overloads")
private static final class OfDouble
extends EmptyNode<Double, double[], DoubleConsumer>
implements Node.OfDouble {
Expand Down Expand Up @@ -880,6 +883,7 @@ public String toString() {
}
}

@SuppressWarnings("overloads")
static final class OfInt
extends ConcNode.OfPrimitive<Integer, IntConsumer, int[], Spliterator.OfInt, Node.OfInt>
implements Node.OfInt {
Expand All @@ -894,6 +898,7 @@ public Spliterator.OfInt spliterator() {
}
}

@SuppressWarnings("overloads")
static final class OfLong
extends ConcNode.OfPrimitive<Long, LongConsumer, long[], Spliterator.OfLong, Node.OfLong>
implements Node.OfLong {
Expand All @@ -908,6 +913,7 @@ public Spliterator.OfLong spliterator() {
}
}

@SuppressWarnings("overloads")
static final class OfDouble
extends ConcNode.OfPrimitive<Double, DoubleConsumer, double[], Spliterator.OfDouble, Node.OfDouble>
implements Node.OfDouble {
Expand Down Expand Up @@ -1160,6 +1166,7 @@ public void forEachRemaining(T_CONS consumer) {
}
}

@SuppressWarnings("overloads")
private static final class OfInt
extends OfPrimitive<Integer, IntConsumer, int[], Spliterator.OfInt, Node.OfInt>
implements Spliterator.OfInt {
Expand All @@ -1169,6 +1176,7 @@ private static final class OfInt
}
}

@SuppressWarnings("overloads")
private static final class OfLong
extends OfPrimitive<Long, LongConsumer, long[], Spliterator.OfLong, Node.OfLong>
implements Spliterator.OfLong {
Expand All @@ -1178,6 +1186,7 @@ private static final class OfLong
}
}

@SuppressWarnings("overloads")
private static final class OfDouble
extends OfPrimitive<Double, DoubleConsumer, double[], Spliterator.OfDouble, Node.OfDouble>
implements Spliterator.OfDouble {
Expand Down
3 changes: 3 additions & 0 deletions src/java.base/share/classes/java/util/stream/Sink.java
Expand Up @@ -186,6 +186,7 @@ default void accept(double value) {
* {@code accept(int)}, and wires {@code accept(Integer)} to bridge to
* {@code accept(int)}.
*/
@SuppressWarnings("overloads")
interface OfInt extends Sink<Integer>, IntConsumer {
@Override
void accept(int value);
Expand All @@ -203,6 +204,7 @@ default void accept(Integer i) {
* {@code accept(long)}, and wires {@code accept(Long)} to bridge to
* {@code accept(long)}.
*/
@SuppressWarnings("overloads")
interface OfLong extends Sink<Long>, LongConsumer {
@Override
void accept(long value);
Expand All @@ -220,6 +222,7 @@ default void accept(Long i) {
* {@code accept(double)}, and wires {@code accept(Double)} to bridge to
* {@code accept(double)}.
*/
@SuppressWarnings("overloads")
interface OfDouble extends Sink<Double>, DoubleConsumer {
@Override
void accept(double value);
Expand Down
Expand Up @@ -720,6 +720,7 @@ else if (splSpineIndex == lastSpineIndex) {
/**
* An ordered collection of {@code int} values.
*/
@SuppressWarnings("overloads")
static class OfInt extends SpinedBuffer.OfPrimitive<Integer, int[], IntConsumer>
implements IntConsumer {
OfInt() { }
Expand Down Expand Up @@ -785,6 +786,7 @@ public PrimitiveIterator.OfInt iterator() {
}

public Spliterator.OfInt spliterator() {
@SuppressWarnings("overloads")
class Splitr extends BaseSpliterator<Spliterator.OfInt>
implements Spliterator.OfInt {
Splitr(int firstSpineIndex, int lastSpineIndex,
Expand Down Expand Up @@ -833,6 +835,7 @@ public String toString() {
/**
* An ordered collection of {@code long} values.
*/
@SuppressWarnings("overloads")
static class OfLong extends SpinedBuffer.OfPrimitive<Long, long[], LongConsumer>
implements LongConsumer {
OfLong() { }
Expand Down Expand Up @@ -899,6 +902,7 @@ public PrimitiveIterator.OfLong iterator() {


public Spliterator.OfLong spliterator() {
@SuppressWarnings("overloads")
class Splitr extends BaseSpliterator<Spliterator.OfLong>
implements Spliterator.OfLong {
Splitr(int firstSpineIndex, int lastSpineIndex,
Expand Down Expand Up @@ -947,6 +951,7 @@ public String toString() {
/**
* An ordered collection of {@code double} values.
*/
@SuppressWarnings("overloads")
static class OfDouble
extends SpinedBuffer.OfPrimitive<Double, double[], DoubleConsumer>
implements DoubleConsumer {
Expand Down Expand Up @@ -1013,6 +1018,7 @@ public PrimitiveIterator.OfDouble iterator() {
}

public Spliterator.OfDouble spliterator() {
@SuppressWarnings("overloads")
class Splitr extends BaseSpliterator<Spliterator.OfDouble>
implements Spliterator.OfDouble {
Splitr(int firstSpineIndex, int lastSpineIndex,
Expand Down
Expand Up @@ -572,6 +572,7 @@ public void forEachRemaining(T_CONS consumer) {
}
}

@SuppressWarnings("overloads")
static final class OfInt
extends OfPrimitive<Integer, IntConsumer, Spliterator.OfInt>
implements Spliterator.OfInt {
Expand All @@ -581,6 +582,7 @@ static final class OfInt
}
}

@SuppressWarnings("overloads")
static final class OfLong
extends OfPrimitive<Long, LongConsumer, Spliterator.OfLong>
implements Spliterator.OfLong {
Expand All @@ -590,6 +592,7 @@ static final class OfLong
}
}

@SuppressWarnings("overloads")
static final class OfDouble
extends OfPrimitive<Double, DoubleConsumer, Spliterator.OfDouble>
implements Spliterator.OfDouble {
Expand Down Expand Up @@ -815,6 +818,7 @@ public void forEachRemaining(T_CONS action) {
protected abstract T_CONS emptyConsumer();
}

@SuppressWarnings("overloads")
static final class OfInt extends OfPrimitive<Integer, Spliterator.OfInt, IntConsumer>
implements Spliterator.OfInt {
OfInt(Spliterator.OfInt s, long sliceOrigin, long sliceFence) {
Expand All @@ -839,6 +843,7 @@ protected IntConsumer emptyConsumer() {
}
}

@SuppressWarnings("overloads")
static final class OfLong extends OfPrimitive<Long, Spliterator.OfLong, LongConsumer>
implements Spliterator.OfLong {
OfLong(Spliterator.OfLong s, long sliceOrigin, long sliceFence) {
Expand All @@ -863,6 +868,7 @@ protected LongConsumer emptyConsumer() {
}
}

@SuppressWarnings("overloads")
static final class OfDouble extends OfPrimitive<Double, Spliterator.OfDouble, DoubleConsumer>
implements Spliterator.OfDouble {
OfDouble(Spliterator.OfDouble s, long sliceOrigin, long sliceFence) {
Expand Down Expand Up @@ -1128,6 +1134,7 @@ public void forEachRemaining(T_CONS action) {
protected abstract T_BUFF bufferCreate(int initialCapacity);
}

@SuppressWarnings("overloads")
static final class OfInt
extends OfPrimitive<Integer, IntConsumer, ArrayBuffer.OfInt, Spliterator.OfInt>
implements Spliterator.OfInt, IntConsumer {
Expand Down Expand Up @@ -1163,6 +1170,7 @@ protected Spliterator.OfInt makeSpliterator(Spliterator.OfInt s) {
}
}

@SuppressWarnings("overloads")
static final class OfLong
extends OfPrimitive<Long, LongConsumer, ArrayBuffer.OfLong, Spliterator.OfLong>
implements Spliterator.OfLong, LongConsumer {
Expand Down Expand Up @@ -1198,6 +1206,7 @@ protected Spliterator.OfLong makeSpliterator(Spliterator.OfLong s) {
}
}

@SuppressWarnings("overloads")
static final class OfDouble
extends OfPrimitive<Double, DoubleConsumer, ArrayBuffer.OfDouble, Spliterator.OfDouble>
implements Spliterator.OfDouble, DoubleConsumer {
Expand Down
3 changes: 3 additions & 0 deletions src/java.base/share/classes/java/util/stream/Streams.java
Expand Up @@ -804,6 +804,7 @@ public void forEachRemaining(T_CONS action) {
}
}

@SuppressWarnings("overloads")
static class OfInt
extends ConcatSpliterator.OfPrimitive<Integer, IntConsumer, Spliterator.OfInt>
implements Spliterator.OfInt {
Expand All @@ -812,6 +813,7 @@ static class OfInt
}
}

@SuppressWarnings("overloads")
static class OfLong
extends ConcatSpliterator.OfPrimitive<Long, LongConsumer, Spliterator.OfLong>
implements Spliterator.OfLong {
Expand All @@ -820,6 +822,7 @@ static class OfLong
}
}

@SuppressWarnings("overloads")
static class OfDouble
extends ConcatSpliterator.OfPrimitive<Double, DoubleConsumer, Spliterator.OfDouble>
implements Spliterator.OfDouble {
Expand Down
Expand Up @@ -275,9 +275,8 @@ public static EnumSet<Flag> asFlagSet(long flags) {
public static final long THROWS = 1L<<47;

/**
* Flag that marks potentially ambiguous overloads
* Currently available: Bit 48.
*/
public static final long POTENTIALLY_AMBIGUOUS = 1L<<48;

/**
* Flag that marks a synthetic method body for a lambda expression
Expand Down Expand Up @@ -526,7 +525,7 @@ public enum Flag {
DEPRECATED_ANNOTATION(Flags.DEPRECATED_ANNOTATION),
DEPRECATED_REMOVAL(Flags.DEPRECATED_REMOVAL),
HAS_RESOURCE(Flags.HAS_RESOURCE),
POTENTIALLY_AMBIGUOUS(Flags.POTENTIALLY_AMBIGUOUS),
// Bit 48 is currently available
ANONCONSTR_BASED(Flags.ANONCONSTR_BASED),
NAME_FILLED(Flags.NAME_FILLED),
PREVIEW_API(Flags.PREVIEW_API),
Expand Down
Expand Up @@ -5563,6 +5563,7 @@ private void attribClassBody(Env<AttrContext> env, ClassSymbol c) {
// yet different return types). (JLS 8.4.8.3)
chk.checkCompatibleSupertypes(tree.pos(), c.type);
chk.checkDefaultMethodClashes(tree.pos(), c.type);
chk.checkPotentiallyAmbiguousOverloads(tree, c.type);
}

// Check that class does not import the same parameterized interface
Expand Down

1 comment on commit 1e3c9fd

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.