NL8xxx: portability warnings
The 12 codes of band 8. Diagnostics says what a code promises and how a rule's fragment is matched.
NL8001
The message of a warning --warn-portability turns on contains:
…counts UTF-8 bytes here, and UTF-16 units in TypeScript…
// NL8001: a UTF-8 byte count returned as `main`'s exit code, which TypeScript
// counts in UTF-16 units.
export const main = (): number => {
const name = "héllo";
return name.length;
};
`name.length` counts UTF-8 bytes here, and UTF-16 units in TypeScript, and `main` returns it as the exit code
NL8002
The message of a warning --warn-portability turns on contains:
…panics here outside its receiver's bounds, where TypeScript clamps…
// NL8002: a `slice` bound nothing proves inside the string, which panics here
// where TypeScript clamps it.
export const main = (): number => {
const s = "abcdef";
const at = s.length + 1;
console.log(s.slice(0, at));
return 0;
};
`s.slice(0, at)` panics here outside its receiver's bounds, where TypeScript clamps: `at` is not proven inside `[0, length]`, and `substring` clamps in both
NL8003
The message of a warning --warn-portability turns on contains:
…is copied into the array here, and TypeScript stores the same object…
// NL8003: a record pushed into an array, then written, then read through the array.
interface Point {
x: i32;
y: i32;
}
export const main = (): number => {
const ps: Point[] = [];
const p: Point = { x: 1, y: 2 };
ps.push(p);
p.x = 9;
return ps[0].x;
};
`p` is copied into the array here, and TypeScript stores the same object, so the later write `p.x = 9` (line 11) is not seen through `ps`
NL8004
The message of a warning --warn-portability turns on contains:
…overwrites the element a reference still reads, and TypeScript replaces the object instead…
// NL8004: a store over a slot an element reference still reads.
interface Point {
x: i32;
y: i32;
}
export const main = (): number => {
const ps: Point[] = [{ x: 1, y: 2 }];
const r = ps[0];
ps[0] = { x: 3, y: 4 };
return r.x;
};
`ps[0] = { x: 3, y: 4 }` overwrites the element a reference still reads, and TypeScript replaces the object instead (`r`, line 11)
NL8005
The message of a warning --warn-portability turns on contains:
…is filled with zeros here, and with holes in TypeScript…
// NL8005: a zero-filled `new Array<f64>(n)`, which TypeScript fills with holes.
export const main = (): number => {
const n = 4;
const xs = new Array<f64>(n);
return xs.length;
};
`new Array<f64>(n)` is filled with zeros here, and with holes in TypeScript, which read back as `undefined`
NL8006
The message of a warning --warn-portability turns on contains:
…truncates here, and TypeScript divides exactly
// NL8006: an integer `/` truncates, where TypeScript keeps the fraction.
export const main = (): number => {
const n: i32 = 7;
return n / 2;
};
this `/` on i32 truncates here, and TypeScript divides exactly
NL8007
The message of a warning --warn-portability turns on contains:
…wraps here, and TypeScript keeps counting past the range
// NL8007: a u8 `+` wraps at 256, where TypeScript keeps counting.
export const main = (): number => {
const level: u8 = 250;
const next: u8 = level + 10;
return toI32(next);
};
this `+` on u8 wraps here, and TypeScript keeps counting past the range
NL8008
The message of a warning --warn-portability turns on contains:
…reads back signed here, and unsigned in TypeScript
// NL8008: an i32 `>>>` reads back signed, where TypeScript reads it unsigned.
export const main = (): number => {
const x: i32 = -8;
return x >>> 0;
};
this `>>>` on i32 reads back signed here, and unsigned in TypeScript
NL8009
The message of a warning --warn-portability turns on contains:
…is a 64-bit integer here, and a double in TypeScript…
// NL8009: an i64 binding is a double in TypeScript.
export const main = (): number => {
const total: i64 = 3;
return toI32(total);
};
`total` is a 64-bit integer here, and a double in TypeScript, which rounds past 2^53
NL8010
The message of a warning --warn-portability turns on contains:
…follows the native NaN and signed-zero rules here, not JavaScript's
Retired: the portability warning's float Math.min/max/round row; they lower to compare-and-select (llvm.minimum/maximum on wasm) and a copysign now, which answer NaN and -0 as JavaScript does, so no site diverges (tests/cases/port_num_libm pins the quiet)
NL8011
The message of a warning --warn-portability turns on contains:
…prints a negative zero as 0 here, and Node's console prints -0
Retired: the portability warning's printed negative zero; the reference reading's console (runtime/nish.mjs) prints String(x), so -0 prints 0 there as it does natively and no site diverges (tests/cases/port_num_negzero pins the quiet)
NL8012
The message of a warning --warn-portability turns on contains:
…is never instantiated, and its body needs the checker's types to translate…
nl8012_generic_stub.ts (compiled with --emit-ts build/test/wordings/nl8012_generic_stub):
// NL8012: a generic no instance reaches is not typed by the checker, and an
// `i64` in its body is a `bigint` under Node, so `--emit-ts` writes it with a
// body that throws and says so.
const wide = <T>(xs: T[]): i64 => {
return toI64(xs.length) + 1
}
export const main = (): number => 0
`wide` is never instantiated, and its body needs the checker's types to translate: --emit-ts writes it as a stub that throws

