NL3xxx: modules and the driver

The 57 codes of band 3. Diagnostics says what a code promises and how a rule's fragment is matched.

NL3001

The message of an error contains:

…--target: unsupported target `

No program provokes it: --target: unsupported target is a usage error (exit 2), not a diagnostic

NL3002

The message of an error contains:

…, not in your program. Please report it with the input file and

No program provokes it: a line of the exit-70 report, printed beside the diagnostic rather than as one

NL3003

The message of an error contains:

…: internal compiler error

No program provokes it: the internal-error diagnostic carries the INTERNAL constant NL0003, not this fragment

NL3005

The message of an error contains:

…=1 for the stack trace)

No program provokes it: a line of the exit-70 report

NL3006

The message of an error contains:

Cannot find module `

NL3007

The message of an error contains:

…the command line at https://github.com/amritk/nish/issues

No program provokes it: a line of the exit-70 report

NL3008

The message of an error contains:

…unknown option: …

No program provokes it: unknown option: is a usage error (exit 2), not a diagnostic

NL3009

The message of an error contains:

…; a class or interface name is still program-wide, so two packages cannot both declare one

NL3010

The message of an error contains:

…; a function name must be unique across the program, and an instantiation is named after its template

nl3010_generic_redeclared.ts:

// NL3010: two modules declaring one generic name. An instantiation is named
// after its template, so both would emit `@identity$i32` — the same collision
// the plain-function rule refuses, one namespace up. Two *packages* may each
// keep a private `identity<T>`, because an instantiation carries its package's
// prefix (`tests/link/package_generic`); this is one package, so they clash.
//
// `anchor` is imported only to load the other module; the clash is between the
// two `identity` templates and not between anything this file names.
import { anchor } from "./wordings_generic";

const identity = <T>(x: T): T => x;

export const main = (): i32 => identity(1) + anchor();
Generic function `identity` is also defined in tests/wordings/nl3010_generic_redeclared.ts; a function name must be unique across the program, and an instantiation is named after its template

NL3011

The message of an error contains:

` is not part of the standard library (it has: …

NL3012

The message of an error contains:

…: --emit-napi-async requires --threads (its exports allocate on a worker thread)

No program provokes it: --emit-napi-async requires --threads is a usage error (exit 2), not a diagnostic

NL3013

The message of an error contains:

…; a class or interface name must be unique across the program, and an instantiation is named after its template

NL3014

The message of an error contains:

… entry point: its `exports` gave this compiler no file to compile for `

NL3015

The message of an error contains:

` directory above the importing module has it

NL3016

The message of an error contains:

` specifier names a module inside it, so no segment may be empty or begin with a `.`

NL3017

The message of an error contains:

`, and this program is compiling in …

NL3018

The message of an error contains:

` needs a newer compiler: its `engines.

NL3019

The message of an error contains:

`, which is not a range this compiler reads: the one it accepts is a floor, `>=X.Y.Z` or `>=X.Y`

NL3020

The message of an error contains:

`, because that entry declares none of the conditions this compiler compiles source from (`

NL3021

The message of an error contains:

… is not well-formed JSON, so this compiler could not read an entry point out of it

NL3022

The message of an error contains:

…; a constructor or method is named after its class, so two classes that share a name anywhere in the program cannot both declare it, whether or not either is exported; rename one of the classes

No program provokes it: a member symbol carries its package's prefix, so only two same-named structs of one package share one; declaredStructs compares each with its own package's first and refuses the pair first, a declared class as NL3028 and an instantiation at its template as NL3013, and skips their members (#193)

NL3023

The message of an error contains:

…; a constructor or method is named after its class, so two classes that share a name within one package cannot both declare it, whether or not either is exported; rename one of the classes

No program provokes it: NL3022 inside a package, preempted by NL3028 or NL3013 the same way (#193)

NL3024

The message of an error contains:

…; exported names must be unique across the program

nl3024_exported_function_clash.ts:

// NL3024: `twice` is exported here and from `nl3_clash/lib.ts`, and an exported
// function's symbol is its name, so two modules cannot both export one.
import { anchor } from "./nl3_clash/lib";

export const twice = (x: i32): i32 => x + x;

export const main = (): i32 => twice(anchor());
Exported function `twice` is also defined in tests/wordings/nl3024_exported_function_clash.ts; exported names must be unique across the program

NL3025

The message of an error contains:

…; exported names must be unique within the package that declares them

nl3025_package_exported_function_clash.ts:

// NL3025: NL3024 inside a package. Both of `clash_export`'s modules export
// `twice`, which is one package-scoped symbol.
import { run } from "./nl3_clash/node_modules/clash_export/index";

export const main = (): i32 => run();
Exported function `twice` is also defined in tests/wordings/nl3_clash/node_modules/clash_export/index.ts; exported names must be unique within the package that declares them

NL3026

The message of an error contains:

…; a function name must be unique across the program whether or not it is exported, because the whole-program attribute analysis is keyed by symbol name

nl3026_function_clash.ts:

// NL3026: `hidden` is exported by neither module, and still clashes with
// `nl3_clash/lib.ts`'s, because the whole-program attribute analysis is keyed
// by symbol name and a module-private function has no prefix of its own.
import { anchor } from "./nl3_clash/lib";

const hidden = (): i32 => 4;

export const main = (): i32 => hidden() + anchor();
Function `hidden` is also defined in tests/wordings/nl3026_function_clash.ts; a function name must be unique across the program whether or not it is exported, because the whole-program attribute analysis is keyed by symbol name

NL3027

The message of an error contains:

…; a function name must be unique within its own package whether or not it is exported, because the whole-program attribute analysis is keyed by the package-scoped symbol

nl3027_package_function_clash.ts:

// NL3027: NL3026 inside a package. `clash_internal`'s two modules each keep a
// private `hidden`, which is one package-scoped symbol.
import { run } from "./nl3_clash/node_modules/clash_internal/index";

export const main = (): i32 => run();
Function `hidden` is also defined in tests/wordings/nl3_clash/node_modules/clash_internal/index.ts; a function name must be unique within its own package whether or not it is exported, because the whole-program attribute analysis is keyed by the package-scoped symbol

NL3028

The message of an error contains:

…; a class or interface name must be unique across the program whether or not it is exported, because a struct type is identified by its name alone

nl3028_class_name_clash.ts:

// NL3028: this module and `nl3_clash/lib.ts` each declare a class `Base`. A
// struct type is identified by its name alone, so the two would be one type;
// the later declaration in load order, `lib.ts`'s, is refused (#193). The two
// also share `Base.constructor`, which is not reported a second time.
import { anchor } from "./nl3_clash/lib";

class Base {
  x: i32 = 0;

  constructor(x: i32) {
    this.x = x;
  }
}

export const main = (): i32 => new Base(anchor()).x;
Class `Base` is also declared in tests/wordings/nl3028_class_name_clash.ts; a class or interface name must be unique across the program whether or not it is exported, because a struct type is identified by its name alone

NL3029

The message of an error contains:

… compiles one copy of a package per program, so every import of it has to reach the same directory

NL3030

The message of an error contains:

…`; a class or interface name is program-wide, so one program cannot have both (rename this one)

nl3030_map_clash.ts:

// NL3030: this module declares a class `Map` of its own, which is legal by
// itself, while `map_clash_global.ts` names the global one. A class name is
// program-wide, so the program cannot have both.
import { counted } from "./map_clash_global";

class Map {
  size: i32 = 0;
}

export const main = (): i32 => new Map().size + counted();
`Map` is declared here and tests/wordings/map_clash_global.ts uses the global `Map`; a class or interface name is program-wide, so one program cannot have both (rename this one)

NL3031

The message of an error contains:

`, which is no module of this program: an entry is the path of a module the program compiles, relative to the `package.json` that lists it, and one that names nothing would leave the module it meant outside the scope without a word

NL3032

The message of an error contains:

….capabilities` is an object with an `allow` list, a `deny` list or both, each an array of capability names

NL3033

The message of an error contains:

` is no capability: a policy names capabilities as `--emit-capabilities` reports them, one of …

NL3034

The message of an error contains:

` is the opt-in to it, so a policy can only deny it

NL3035

The message of an error contains:

` is both allowed and denied in the root package's capability policy; a policy says one or the other

NL3036

The message of an error contains:

` field is one object, written once, whose keys are `noPanic`, `capabilities`, `host`, `compat` and `netRings`, each written once

NL3037

The message of an error contains:

…, so the references the C library and the runtime make to that name would reach this function instead; rename it

nl3037_exported_c_symbol.ts:

// NL3037: an exported function of the program's own package named after a C
// library function the runtime calls. Its name is its symbol, so the runtime's
// `exit` would call it; it is refused rather than renamed, because an exported
// name is the program's ABI.
export const exit = (code: i32): i32 => code;

export const main = (): i32 => exit(0);
`exit` is the C library's `exit`: an exported function of the program's own package keeps its name as its symbol, so the references the C library and the runtime make to that name would reach this function instead; rename it

NL3038

The message of an error contains:

…, so the module would export two things named `memory` and no host could load it; rename it

nl3038_exported_wasm_memory.ts (compiled with --target wasm32):

// NL3038: an exported function named `memory` in a wasm build. `wasm-ld`
// exports the module's linear memory under that name, so the function would be
// a second `memory` export and Node would refuse the module; it is refused
// rather than renamed, because an exported name is the program's ABI.
export const memory = (n: i32): i32 => n + 1;

export const main = (): i32 => memory(41);
`memory` is the name a wasm module exports its linear memory under: an exported function of the program's own package keeps its name as its symbol, so the module would export two things named `memory` and no host could load it; rename it

NL3039

The message of an error contains:

…; C has one namespace, so every `declare function` of one name must agree on its parameter and return types

NL3040

The message of an error contains:

…; a `declare function` binds the C symbol of its name in every package, so rename the defined function

NL3041

The message of an error contains:

….capabilities.dependencies` is an object that names each dependency once, with an array of the capabilities granted it

NL3042

The message of an error contains:

` is not a gated capability: a dependency is granted only `ffi`, `fs.read`, `fs.write`, `net`, `process.spawn` and `unsafe`, and reaches every other capability without a grant

NL3043

The message of an error contains:

…that names each dependency once with an array of the capabilities it reaches; rewrite it with `--update-capability-lock`

NL3044

The message of an error contains:

… has no Landlock and no seccomp, so build without --sandbox

nl3044_sandbox_darwin.ts (compiled with --sandbox --target aarch64-apple-darwin):

// NL3044: --sandbox installs Landlock and seccomp, which a darwin target does not have.
export const main = (): number => 0;
--sandbox confines a Linux process; aarch64-apple-darwin has no Landlock and no seccomp, so build without --sandbox

NL3045

The message of an error contains:

` names no numeric host: `net` is granted for the IPv4 or IPv6 addresses `nish:net` takes, or a Unix socket's absolute path, one entry per address

NL3046

The message of an error contains:

` names no program: a grant's program is found on `PATH`, or as a path from the root package's directory, when the program is built

NL3047

The message of an error contains:

` names no directory: a grant's directory is resolved from the root package's directory and exists when the program is built

NL3048

The message of an error contains:

` an argument, which only `fs.read` and `fs.write` (a directory), `process.spawn` (a program) and `net` (a host) take: grant `

NL3049

The message of an error contains:

… in a host module: its exports are read without TypeScript's parser, so move that code into a module the host file imports

nl3049_host_regex_literal.ts (compiled with --target wasm32 --host tests/wordings/host/regex.ts):

import { digits } from "./host/regex"
export const f = (): i32 => {
  return digits()
};
A regular expression literal in a host module: its exports are read without TypeScript's parser, so move that code into a module the host file imports

NL3050

The message of an error contains:

…` is a host module, and only a freestanding wasm build imports one: build with `--target wasm32`, or with `--emit-dts` and no `--target`

nl3050_host_module_native.ts (compiled with --host tests/wordings/host/plain.ts):

import { twice } from "./host/plain"
export const main = (): i32 => {
  return twice(2)
};
`./host/plain` is a host module, and only a freestanding wasm build imports one: build with `--target wasm32`, or with `--emit-dts` and no `--target`

nl3050_host_module_wasi.ts (compiled with --target wasm32-wasi --host tests/wordings/host/plain.ts):

// NL3050 under WASI: a WASI program links C, so it imports no host module.
import { twice } from "./host/plain"
export const main = (): i32 => {
  return twice(2)
};
`./host/plain` is a host module, and only a freestanding wasm build imports one: build with `--target wasm32`, or with `--emit-dts` and no `--target`

NL3051

The message of an error contains:

` is the name the wasm loader answers the program's module storage under: …

NL3052

The message of an error contains:

…the file system answers differently on every host

NL3053

The message of an error contains:

…another machine or another program answers from outside this one

NL3054

The message of an error contains:

C code or a host import runs where this compiler cannot pin its bits

NL3055

The message of an error contains:

…` besides: Node copies every own field of the instance a value holds, and the native copy only the interface's, so spread a value of a class type, or set the fields by name

nl3055_object_spread_width.ts:

// NL3055: A value of an interface type may hold a class instance with more fields; Node
// copies all of them and the native copy only the interface's, so a spread of
// such an interface is refused.
interface Named {
  name: i32;
}

interface Tagged {
  name: i32;
  tag: i32;
}

class Item implements Named {
  name: i32 = 1;
  weight: i32 = 2;
}

export const tag = (n: Named): i32 => {
  const t: Tagged = { ...n, tag: 3 };
  return t.tag;
};

export const main = (): i32 => tag(new Item());
Spread of `Named` into `Tagged` may spread an instance of `Item`, which implements it with field `weight` besides: Node copies every own field of the instance a value holds, and the native copy only the interface's, so spread a value of a class type, or set the fields by name

NL3056

The message of an error contains:

… is no feature of the compatibility dialect: `

NL3057

The message of an error contains:

…, which the root package's `compat` does not allow: a program is compiled in its root package's dialect

NL3058

The message of an error contains:

`: it is how many restricted rings `--sandbox` makes for `NET_LISTEN_RING` before its filter loads, an integer from 1 to …