java-topology/test/langtools/tools/javac/generics/odersky/BadTest.java
russell@unturf.com 0a580b313d undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com

Patches, unit tests, benchmarks, whitepaper, and outreach briefs.
Public domain — no copyright claimed. Use freely.
2026-03-26 17:11:57 -04:00

31 lines
1.1 KiB
Java

/*
* @test /nodynamiccopyright/
* @summary Negative regression test from odersky
* @author odersky
*
* @compile/fail/ref=BadTest-old.out -XDrawDiagnostics --release 15 BadTest.java
* @compile/fail/ref=BadTest.out -XDrawDiagnostics BadTest.java
*/
class BadTest {
static class Main {
static <B> List<B> nil() { return new List<B>(); }
static <A> List<A> cons(A x, List<A> xs) { return xs.prepend(x); }
static <A> Cell<A> makeCell(A x) { return new Cell<A>(x); }
static <A> A id(A x) { return x; }
public static void meth() {
List<Cell<String>> as = nil().prepend(makeCell(null));
List<Cell<String>> bs = cons(makeCell(null), nil());
List<String> xs = id(nil());
List<String> ys = cons("abc", id(nil()));
List<String> zs = id(nil()).prepend("abc");
List<Cell<String>> us = id(nil()).prepend(makeCell(null));
List<Cell<String>> vs = cons(makeCell(null), id(nil()));
System.out.println(nil() instanceof List<String>);
nil();
}
}
}