---
title: "규칙 7.4: 표현식과 문, TypeShade 셰이더 언어 설계 규칙과 그 근거, 출처, 검증 방식"
description: "TypeShade 언어 설계 규칙 7.4(표현식과 문)입니다. A shift amount the compiler can fold must be in 0 to 31…"
url: https://typeshade.dev/ko/reference/rules/7-4/
language: ko
---

# 규칙 7.4

7장, 표현식과 문 테스트

A shift amount the compiler can fold must be in 0 to 31; a divisor the compiler can prove to be zero must be refused where the division is lowered.

규칙 본문과 그 아래 항목은 설계 문서에 적힌 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.

## 근거

WGSL takes a shift amount modulo the bit width and makes a const-expression amount at or past it a shader-creation error, and makes a const-expression divisor of zero a shader-creation error, giving `x` only where the divisor is not known before shader execution; a program Tint refuses should not compile, and a divisor that is certainly zero or an amount certainly past the width is most likely a mistake. A run-time amount takes WGSL’s answer on every target ([Rule 11.12](https://typeshade.dev/ko/reference/rules/11-12/)). A run-time divisor takes it too where an operand has a declared integer type: `ii / (ii + 3)` with `ii: i32` is `ii` where `ii + 3` is 0. Where no operand has a declared type and a position that states an integer type reads the quotient ([Rule 5.1](https://typeshade.dev/ko/reference/rules/5-1/)), a divisor that is zero at run time gives TypeScript’s value, 0. It does not give WGSL’s `x / 0 = x` (the owner’s decision of 2026-11-17, Amendment A8 of change 0134).

## 출처

[Bit Expressions](https://gpuweb.github.io/gpuweb/wgsl/#bit-expr) (the concrete shift rows); [Arithmetic Expressions](https://gpuweb.github.io/gpuweb/wgsl/#arithmetic-expr); surface §22 ([#71](https://github.com/typeshade/typeshade/issues/71), [#68](https://github.com/typeshade/typeshade/issues/68)).

## 검증 방식

테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.

컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.

`TS8003 TYPE_MISMATCH` from `src/compiler/ts/lower/expression.ts`, where `lowerBinary` folds a shift amount through `foldConstNumber` (`src/compiler/ts/loop-bound.ts`) and a divisor through `divisorIsZero`; `src/compiler/ts/lower/statement.ts` (`lowerBitwiseAssignOp`) for a compound shift assignment; and `foldsToZero` in `src/compiler/ts/module-const.ts`, which refuses a module const whose initializer divides by a proven zero; pinned by `src/compiler/ts/shift-amount.test.ts` and `src/compiler/ts/zero-divisor.test.ts`.

커밋 af54ddad5에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.

- [`src/compiler/ts/loop-bound.ts:4`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/loop-bound.ts#L4)
- [`src/compiler/ts/lower/expression.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression.ts#L1)
- [`src/compiler/ts/lower/statement.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/statement.ts#L1)
- [`src/compiler/ts/module-const.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/module-const.ts#L1)
- [`src/compiler/ts/shift-amount.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/shift-amount.test.ts#L1)
- [`src/compiler/ts/zero-divisor.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/zero-divisor.test.ts#L1)

## 설명하는 절

커밋 af54ddad5의 언어 문서에서 이 규칙을 설명하는 절입니다.

- [§22 Constant checks on a shift amount and a divisor](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#22-constant-checks-on-a-shift-amount-and-a-divisor)

## 적용하는 오류 코드

규칙이 Enforced by 항목에서 가리키는 진단 코드와, 레지스트리 설명에서 이 규칙을 가리키는 진단 코드입니다.

**[`TS8003`](https://typeshade.dev/ko/reference/errors/ts8003/) `TYPE_MISMATCH`**

연산자나 조건, 선언, 반환, 인자처럼 두 값이 만나는 자리에서 타입이 서로 맞지 않거나, 검사로 좁히지 않은 선택적 값(`T | undefined`, `T | null`, `T | null | undefined`)을 읽거나([규칙 7.10](https://typeshade.dev/ko/reference/rules/7-10/)), 컴파일러가 접는 상수를 WGSL이 거부합니다. 31을 넘는 시프트 양, 0인 제수, 서로 엇갈린 clamp 경계, 범위를 넘는 `f32` 값, `Math.pow(-2., 2.)`처럼 정의역 밖에서 부르는 내장 함수가 그렇습니다.

## 함께 보기

- [규칙 7.3](https://typeshade.dev/ko/reference/rules/7-3/) 테스트
- [규칙 7.5](https://typeshade.dev/ko/reference/rules/7-5/) 테스트
- [규칙 5.1](https://typeshade.dev/ko/reference/rules/5-1/)
- [규칙 11.12](https://typeshade.dev/ko/reference/rules/11-12/)
- [설계 규칙](https://typeshade.dev/ko/reference/rules/)
- [오류 코드](https://typeshade.dev/ko/reference/errors/)

## 소스

커밋 af54ddad5의 규칙 원문:

- [`docs/language-design.md:688`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/language-design.md#L688) (설계 문서)
- [`reqs/rules/RULE-0704.md`](https://github.com/typeshade/typeshade/blob/af54ddad5/reqs/rules/RULE-0704.md) (추적 항목)
