TS8020
이 페이지에서

TS8020

프런트엔드 코드 FUNCTION_SHAPE

A function declaration or parameter shape TypeShade does not support (missing name or body, optional/rest/destructured parameter).

레지스트리 설명과 컴파일러 메시지는 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.

예제

example.shade.ts
"use typeshade"
function shade(x?: f32): f32 {
return 0.5
}
@fragment
export function main(@location(0) uv: vec2): vec4 {
return vec4(uv, shade(uv.x), 1.)
}

빌드할 때 고정된 컴파일러로 이 프로그램을 컴파일하면 다음 진단이 나옵니다.

TS8020 error, 3행: Optional parameter "x" is not supported: a shader value is always present, so there is no "absent" for the body to test. Give it a default instead, "x: T = ...", which a call that omits it fills in.

고치는 법

같은 프로그램을 고친 모습입니다. 진단 없이 컴파일됩니다.

example.shade.ts
"use typeshade"
function shade(x: f32 = 0.5): f32 {
return x
}
@fragment
export function main(@location(0) uv: vec2): vec4 {
return vec4(uv, shade(uv.x), 1.)
}

이 코드가 적용하는 규칙

규칙 8.8 테스트
A parameter an author writes must be passed by value, unless it is declared Ref<T>, which names the caller’s place (Rule 8.25); there must be no pointer values.
규칙 8.18 테스트
A function whose parameter has a function type, written out (f: (x: f32) => f32) or through a type alias of one, takes a function: a function declared at the top of the file or of a namespace, a method, a static method, a constructor, a field that holds a function (Rule 8.16) and a local function (Rule 8.17).
규칙 8.19 테스트
A function that writes no return type returns what its body does, as TypeScript infers it: a function of the file or of a namespace, a local function (Rule 8.17), each instance of a generic function (Rule 8.9) and of a function that takes a function (Rule 8.18), a method, a getter and a field that holds a function (Rule 8.16) take the type of their first return with a value, the returns after it are typed against that type as against a written one, and one with no such return returns nothing.
규칙 8.23 테스트
A kernel function’s parameter of an array with no size is the caller’s storage, passed by reference: the body reads and writes its elements in place, reads its .length, and cannot assign it whole; whether the body writes it decides its access.

함께 보기

소스

커밋 c66579bf에서 컴파일러가 이 코드를 내는 곳입니다. 파일마다 한 줄씩 적었습니다.

이 페이지 편집 문제 보고