INRIA / INRIA/spoon

[Bug]: Type reference building logic fails within lambda bodies

Open
#5,477 0 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

### Describe the bug

Something seems to go wrong with type reference parsing within method bodies when `extends` is involved. The following fails with the included stack trace:
```java
Launcher.parseClass("""
public class Test {
public static void test() {
final Supplier supplier = () -> {
final Supplier> supplier1 = () -> a -> a;
return supplier1;
};
}
}""");
```
However, each of the following succeed:
```java
Launcher.parseClass("""
public class Test {
public static void test() {
final Supplier supplier = () -> {
final Supplier> supplier1 = () -> a -> a;
return supplier1;
};
}
}""");
```
```java
Launcher.parseClass("""
public class Test {
public static void test() {
final Supplier supplier = () -> {
final Supplier> supplier1 = () -> () -> new Object();
return supplier1;
};
}
}""");
```
```java
Launcher.parseClass("""
public class Test {
public static void test() {
final Supplier> supplier = () -> a -> a;
}
}""");
```
In other words, it only seems to apply with the combination of the local definition being within a lambda, the `extends` being present, and the nested type being parameterized by more than one type (so that it is split on the comma when the outer one is being processed)

### Actual output

```Java
Caused by: spoon.JLSViolation: Not allowed javaletter or keyword in identifier found. See JLS for correct identifier. Identifier: Function

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.