Skip to content

SI-7741: Be more tolerant of absent inner classfiles and non-Scala interface members#4386

Merged
lrytz merged 1 commit intoscala:2.11.xfrom
retronym:ticket/7741
Apr 9, 2015
Merged

SI-7741: Be more tolerant of absent inner classfiles and non-Scala interface members#4386
lrytz merged 1 commit intoscala:2.11.xfrom
retronym:ticket/7741

Conversation

@alewando
Copy link

Modifies ClassfileParser to avoid forcing the type information of members of non-Scala defined interfaces unnecessarily, and defers failures due to completely absent inner classes. Although these classes may not conform to expectations for javac-compiled classes, they are still valid JVM class files (in this case produced by the Groovy compiler) and should be supported by scalac. In addition to discussion on SI-7741 see also https://groups.google.com/d/msg/scala-internals/lGE15Ly6xHU/q1LLfS3w9R0J.

@scala-jenkins scala-jenkins added this to the 2.11.7 milestone Mar 17, 2015
@retronym retronym self-assigned this Mar 23, 2015
@retronym
Copy link
Member

/rebuild

@retronym
Copy link
Member

@alewando I've squashed the commits together and tidied up the code a little.

1. Avoid forcing info of non-Scala interface members

This avoids parsing the ostensibly malformed class definitions that
correspond to a Groovy lambda defined in an interface.

2. Be more tolerant of absent inner classfiles

Taking a leaf out of javac's book (see transcript below),
we can use stub symbols for InnerClass entries that don't
have corresponding class files on the compilation classpath.

This will limit failures to code that directly refers to the
inner class, rather than any code that simply refers to the
enclosing class.

It seems that groovyc has a habit of emitting incongrous
bytecode in this regard. But this change seems generally
useful.

```
% cat sandbox/{Test,Client}.java
public class Test {
	public class Inner {}
}
public class Client {
	public Test.Inner x() { return null; }
}

% javac -d . sandbox/Test.java && javac -classpath . sandbox/Client.java

% javac -d . sandbox/Test.java && rm 'Test$Inner.class' && javac -classpath . sandbox/Client.java
sandbox/Client.java:2: error: cannot access Inner
	public Test.Inner x() { return null; }
	           ^
  class file for Test$Inner not found
1 error

% cat sandbox/{Test,Client}.java
public class Test {
	public class Inner {}
}
public class Client {
	public Test.NeverExisted x() { return null; }
}

% javac -classpath . sandbox/Client.java
sandbox/Client.java:2: error: cannot find symbol
	public Test.NeverExisted x() { return null; }
	           ^
  symbol:   class NeverExisted
  location: class Test
1 error

% cat sandbox/{Test,Client}.java
public class Test {
	public class Inner {}
}
public class Client {
	public Test x() { return null; }
}
topic/groovy-interop ~/code/scala2 javac -d . sandbox/Test.java && rm 'Test$Inner.class' && javac -classpath . sandbox/Client.java # allowed
```
@lrytz
Copy link
Member

lrytz commented Mar 27, 2015

/synch

@retronym
Copy link
Member

retronym commented Apr 8, 2015

Review by @lrytz

@retronym retronym assigned lrytz and unassigned retronym Apr 8, 2015
@lrytz
Copy link
Member

lrytz commented Apr 9, 2015

LGTM!

lrytz added a commit that referenced this pull request Apr 9, 2015
SI-7741: Be more tolerant of absent inner classfiles and non-Scala interface members
@lrytz lrytz merged commit 68e0570 into scala:2.11.x Apr 9, 2015
@adriaanm adriaanm added the welcome hello new contributor! label May 26, 2015
@eed3si9n eed3si9n mentioned this pull request Jul 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

welcome hello new contributor!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants