Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression compiling Java in 0.5.0 #2979

Closed
dfabulich opened this issue May 10, 2017 · 4 comments
Closed

Regression compiling Java in 0.5.0 #2979

dfabulich opened this issue May 10, 2017 · 4 comments
Assignees
Labels
P1 I'll work on this now. (Assignee required) under investigation

Comments

@dfabulich
Copy link
Contributor

This repository https://github.com/dfabulich/raw-list-bug builds without error in Bazel 0.4.5 when I run bazel build example, but fails to build in Bazel 0.5.0rc3

build failure message
ERROR: /private/tmp/raw-list-bug/BUILD:1:1: Building example.jar (1 source file) failed: Worker process sent response with exit code: 1.
src/main/java/com/redfin/Example.java:8: error: reference to newArrayList is ambiguous
		newArrayList(newLinkedHashSet(new ArrayList()));
		^
  both method <E#1>newArrayList(Iterable<? extends E#1>) in Example and method <E#2>newArrayList(Iterator<? extends E#2>) in Example match
  where E#1,E#2 are type-variables:
    E#1 extends Object declared in method <E#1>newArrayList(Iterable<? extends E#1>)
    E#2 extends Object declared in method <E#2>newArrayList(Iterator<? extends E#2>)
Target //:example failed to build

It seems like this must be a bug in the compiler; the code is using a raw LinkedHashSet, which is an Iterable, but it is not an Iterator.

The code compiles just fine with Oracle's javac compiler javac 1.8.0_112

Environment info

  • Operating System:
    macOS Sierra 10.12.4

  • Bazel version (output of bazel info release):
    release 0.5rc3 (it works with release 0.4.5)

I tried both the 0.5 version with an embedded JDK and without an embedded JDK, to see if that has an effect; it failed in both versions of Bazel 0.5 with identical error messages.

@kchodorow
Copy link
Contributor

@cushon, could you take a look?

@cushon
Copy link
Contributor

cushon commented May 10, 2017

I think this is going to be fixed by https://bazel-review.googlesource.com/c/10990/

@cushon
Copy link
Contributor

cushon commented May 10, 2017

Verified:

import java.util.*;
abstract class T {
  abstract <E> ArrayList<E> newArrayList(Iterable<? extends E> elements);
  abstract <E> ArrayList<E> newArrayList(Iterator<? extends E> elements);
  abstract <E> LinkedHashSet<E> newLinkedHashSet(Iterable<? extends E> elements);
  {
    newArrayList(newLinkedHashSet(new ArrayList()));
  }
}

Before:

T.java:7: error: reference to newArrayList is ambiguous
    newArrayList(newLinkedHashSet(new ArrayList()));
    ^
  both method <E#1>newArrayList(Iterable<? extends E#1>) in T and method <E#2>newArrayList(Iterator<? extends E#2>) in T match
  where E#1,E#2 are type-variables:
    E#1 extends Object declared in method <E#1>newArrayList(Iterable<? extends E#1>)
    E#2 extends Object declared in method <E#2>newArrayList(Iterator<? extends E#2>)
Note: T.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

After:

Note: T.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

@cushon cushon added P1 I'll work on this now. (Assignee required) Release blocker labels May 10, 2017
@dfabulich
Copy link
Contributor Author

Wait a minute, wait a minute. Bazel 0.5 is using an unreleased Java 9 compiler? While I'm glad that upgrading the compiler to another unreleased Java 9 compiler fixed this bug, this can't be the right thing. https://groups.google.com/d/msg/bazel-discuss/LUfkHkCYOoE/4-Y6ni9DBgAJ

hlopko pushed a commit that referenced this issue May 10, 2017
Fixes #2979

Change-Id: I23e38767e18a90b2262a38bf8f4b347e06d1de8d
hlopko pushed a commit that referenced this issue May 10, 2017
Fixes #2979

Change-Id: I23e38767e18a90b2262a38bf8f4b347e06d1de8d
hlopko pushed a commit that referenced this issue May 11, 2017
Fixes #2979

Change-Id: I23e38767e18a90b2262a38bf8f4b347e06d1de8d
hlopko pushed a commit that referenced this issue May 17, 2017
Fixes #2979

Change-Id: I23e38767e18a90b2262a38bf8f4b347e06d1de8d
hlopko pushed a commit that referenced this issue May 17, 2017
Fixes #2979

Change-Id: I23e38767e18a90b2262a38bf8f4b347e06d1de8d
hlopko pushed a commit that referenced this issue May 23, 2017
Fixes #2979

Change-Id: I23e38767e18a90b2262a38bf8f4b347e06d1de8d
damienmg pushed a commit that referenced this issue May 26, 2017
Fixes #2979

Change-Id: I23e38767e18a90b2262a38bf8f4b347e06d1de8d
hlopko pushed a commit that referenced this issue May 31, 2017
Fixes #2979

Change-Id: I23e38767e18a90b2262a38bf8f4b347e06d1de8d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 I'll work on this now. (Assignee required) under investigation
Projects
None yet
Development

No branches or pull requests

3 participants