Ambiguous method call bug

Answered

Similar to this we've been getting a ambiguous method call error squiggly in IntelliJ IDEA (2018.2.7, but for a while and many different versions.)

Beam has a static method and an instance method for some of its types, mainly `FlatMapElements`

 

public static <InputT, OutputT> FlatMapElements<InputT, OutputT> via(
SimpleFunction<? super InputT, ? extends Iterable<OutputT>> fn) {
........

return new FlatMapElements<>(wrapped, fn, inputType, outputType);
}


public static <OutputT> FlatMapElements<?, OutputT> into(
final TypeDescriptor<OutputT> outputType) {
return new FlatMapElements<>(null, null, null, outputType);
}

public <NewInputT> FlatMapElements<NewInputT, OutputT> via(
SerializableFunction<NewInputT, ? extends Iterable<OutputT>> fn) {
return new FlatMapElements<>((Contextful) Contextful.fn(fn), fn, TypeDescriptors.inputOf(fn), outputType);
}

Here is a sample that triggers the error:

@Test
public void not_an_error() {
final TestPipeline pipeline = TestPipeline.fromOptions(AwsPipelineTestOptions.getOptions());


final PCollection<Integer> inputs = pipeline.apply(TestStream.create(VarIntCoder.of())
.addElements(3, 5, 7)
.advanceWatermarkToInfinity());

PAssert.that(inputs.apply(MapElements.via(new SimpleFunction<Integer, Integer>() {
@Override
public Integer apply(final Integer input) {
return input;
}
}))).containsInAnyOrder(3, 5, 7);


final PCollection<Integer> result =
inputs.apply(FlatMapElements.via(new SimpleFunction<Integer, ImmutableList<Integer>>() {
@Override
public ImmutableList<Integer> apply(final Integer input) {
return ImmutableList.of(1 * input, 3 * input);
}
}));

PAssert.that(result).containsInAnyOrder(3, 9, 5, 15, 7, 21);
}

The IDE complains with a squiggly on


but the code compiles fine and the test passes. (notice that MapElements doesn't error but has the same type shape...)

3
3 comments

Hello Jake,

Is it possible to share sample project example for investigation?

0
Avatar
Permanently deleted user

Here is simpleish self-contained repro. Can be made a little bit simple probably, but this will demonstrate the issue. Just import into intellij and open up TestCaller.java to see the false error.

https://github.com/randomsamples/idea_ambiguous_repro 

1

Jake,

Thanks for the example! I reported issue on YouTrack: https://youtrack.jetbrains.com/issue/IDEA-203450. Please follow it for updates.

0

Please sign in to leave a comment.