TS8004
Front-end code UNKNOWN_FN
A call to a function the file neither declares nor imports, or to a builtin the language removed because ECMAScript spells it, such as arrayLength(xs), whose message names xs.length (Rule 9.9).
The registry has no documentation comment for this constant, so the line above is written by this site from the messages the compiler raises it with.
The registry text and every compiler message on these pages are the compiler's own English.
Example
"use typeshade"
@fragmentexport function main(uv: location<0, vec2>): vec4 { return vec4(uv, brightness(uv), 1.)}Compiled at build time against the pinned compiler, this program gets:
TS8004 error, line 5: Unknown function "brightness". Declare it in this file, or import it from another shader module.
How to fix it
The same program, corrected. It compiles with no diagnostic.
"use typeshade"import { brightness } from "./brightness.shade.ts"
@fragmentexport function main(uv: location<0, vec2>): vec4 { return vec4(uv, brightness(uv), 1.)}It imports from another file of the same program, which compile() reads through its readDocument option:
"use typeshade"
export function brightness(uv: vec2): f32 { return (uv.x + uv.y) * 0.5}The rules this enforces
- Rule 2.1 Test
- Every author-facing name must come from exactly one of three sources:
- Rule 2.2 Test
- A compiler-internal name (§2.1) must not be authorable.
- Rule 7.7 Test
discardmust be written as a bare statement, the identifier alone (discard), and may stand in a fragment entry and in a helper no vertex or compute entry can reach.- Rule 9.9 Test
- A WGSL built-in function, an overload of one, or a §9.3 name must not be authorable when an ECMAScript spelling the compiler supports carries every case it accepts with the same meaning (Rule 1.4).
See also
Source
Where the compiler raises this code at commit af54ddad5, one line per file:
-
src/compiler/ts/lower/expression-call.ts:435(3 sites) -
src/compiler/ts/semantic.ts:616 -
src/compiler/ts/source-file.ts:476 -
src/core/coverage/glsl/common-functions.ts:101 -
src/core/coverage/glsl/float-bits-and-packing.ts:10(2 sites) -
src/core/coverage/glsl/geometric-and-matrix.ts:90(3 sites) -
src/core/coverage/glsl/texture-lookups.ts:32(9 sites) -
src/core/coverage/wgsl/derivative-and-float-functions.ts:209 -
src/core/coverage/wgsl/functions-i32-to-normalize.ts:209 -
src/core/coverage/wgsl/texture-query-and-load-functions.ts:116 -
src/core/coverage/wgsl/texture-sample-functions.ts:31