Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 577351

Summary: inference with diamond error in records in two files
Product: [Eclipse Project] JDT Reporter: Manoj N Palat <manoj.palat>
Component: CoreAssignee: Srikanth Sankaran <srikanth.sankaran>
Status: CLOSED MOVED QA Contact:
Severity: normal    
Priority: P3 CC: forax, manoj.palat, srikanth.sankaran
Version: 4.22   
Target Milestone: 4.24   
Hardware: All   
OS: All   
Whiteboard:

Description Manoj N Palat CLA 2021-11-19 02:18:28 EST
---
import java.util.Objects;

public final class TimeSeries<T> {
  public record Data<T>(long timestamp, T element) {
    public Data {
      Objects.requireNonNull(element);
    }
    @Override
    public String toString() {
      return timestamp + " | " + element;
    }
  }
}

---
import static org.junit.jupiter.api.Assertions.assertThrows;

public class TimeSeriesTest {
  @org.junit.jupiter.api.Test
  public void test() {
assertThrows(NullPointerException.class, () -> new TimeSeries.Data<>(0, null));  
  }
}

Thanks to Remi Forax for providing the test case

two classes in two separate files.

in the method test(), the inference using the diamond syntax fails but it should not.
Comment 1 Manoj N Palat CLA 2022-02-16 05:10:02 EST
Bulk move out of 4.23
Comment 2 Manoj N Palat CLA 2022-02-16 05:11:04 EST
Bulk move out of 4.23
Comment 3 Manoj N Palat CLA 2022-02-16 05:11:25 EST
Bulk move out of 4.23
Comment 4 Manoj N Palat CLA 2022-02-16 05:12:17 EST
Bulk move out of 4.23
Comment 5 Srikanth Sankaran CLA 2023-05-25 04:26:51 EDT
The PR posted at https://github.com/eclipse-jdt/eclipse.jdt.core/pull/1089 for https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1085 fixes this problem also. I have added a regression test from this ticket to that PR for verification purposes.

Closing this as a duplicate of https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1085