---
title: "규칙 7.1: 표현식과 문, TypeShade 셰이더 언어 설계 규칙과 그 근거, 출처, 검증 방식"
description: "TypeShade 언어 설계 규칙 7.1(표현식과 문)입니다. An operator, a swizzle, an index, and a call must mean what WGSL's typing table gives them."
url: https://typeshade.dev/ko/reference/rules/7-1/
language: ko
---

# 규칙 7.1

7장, 표현식과 문 테스트

An operator, a swizzle, an index, and a call must mean what WGSL’s typing table gives them. A swizzle of distinct components on the left of `=` or `op=` takes the type and the operator overloads of the same swizzle read (change 0106). TypeScript’s `==` and `!=` are accepted as aliases of the typed shader comparisons `===` and `!==`; no JavaScript coercion is emitted.

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

## 근거

[Rule 1.1](https://typeshade.dev/ko/reference/rules/1-1/) applied to expressions.

## 출처

[Expressions](https://gpuweb.github.io/gpuweb/wgsl/#expressions), [Arithmetic Expressions](https://gpuweb.github.io/gpuweb/wgsl/#arithmetic-expr), [Bit Expressions](https://gpuweb.github.io/gpuweb/wgsl/#bit-expr).

## 검증 방식

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

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

the compile gate and `src/core/oracle-backend-parity.test.ts`; [`TS8003`](https://typeshade.dev/ko/reference/errors/ts8003/) for a matrix product whose dimensions do not meet ([Rule 4.8](https://typeshade.dev/ko/reference/rules/4-8/), [#169](https://github.com/typeshade/typeshade/issues/169)); `TS8003` for an operator WGSL has no overload for on operands of one type, decided by kind in `src/compiler/ts/lower/operator-kinds.ts` (proposal 0008): arithmetic on a bool, a vector of bools, a struct or an array, `+` and `-` and every compound form on a matrix of doubles, an ordering on anything but a number or a vector of numbers, `===` and `!==` on a matrix, a struct or an array, `&`, `|` and `^` on a matrix, a struct or an array and `^` on a bool or a vector of bools (a float under any of the three is `lowerBinary`’s own `TS8003`, which keeps two whole numbers the front end folds, [#236](https://github.com/typeshade/typeshade/issues/236)), unary `-` on a bool, a matrix, a struct or an array, unary `+` on a struct or an array, and any of them on a texture or a sampler, each sentence naming the operator and the type as written (`Cannot + A: WGSL has no arithmetic on a struct. Write it field by field.`), and the editor’s merge showing that sentence alone, without TypeScript’s TS2365, TS2362, TS2363 or TS2447 on the same operator, or its report about the `number` it types the result as, where that result is read in place, through a member or an element, or through a local declared from it (TS2322, TS2339, TS7053; [Rule 12.4](https://typeshade.dev/ko/reference/rules/12-4/)); pinned by `src/compiler/ts/operators-statements.test.ts`, which reads both halves, and `src/language-service/service.test.ts`.

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

- [`src/compiler/ts/lower/operator-kinds.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/operator-kinds.ts#L1)
- [`src/compiler/ts/operators-statements.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/operators-statements.test.ts#L1)
- [`src/compiler/ts/swizzle-assign.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/swizzle-assign.test.ts#L1)
- [`src/core/oracle-backend-parity.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/oracle-backend-parity.test.ts#L1)
- [`src/language-service/service-output-and-cache.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/service-output-and-cache.test.ts#L1)
- [`src/language-service/service.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/service.test.ts#L1)

## 설명하는 절

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

- [§17 What a `for` loop may say, and what it is told](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#17-what-a-for-loop-may-say-and-what-it-is-told)
- [§27 Boolean vectors](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#27-boolean-vectors)

## 적용하는 오류 코드

규칙이 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.)`처럼 정의역 밖에서 부르는 내장 함수가 그렇습니다.

## 함께 보기

- [규칙 6.11](https://typeshade.dev/ko/reference/rules/6-11/) 테스트
- [규칙 7.2](https://typeshade.dev/ko/reference/rules/7-2/) 테스트
- [규칙 1.1](https://typeshade.dev/ko/reference/rules/1-1/)
- [규칙 4.8](https://typeshade.dev/ko/reference/rules/4-8/)
- [규칙 12.4](https://typeshade.dev/ko/reference/rules/12-4/)
- [설계 규칙](https://typeshade.dev/ko/reference/rules/)
- [오류 코드](https://typeshade.dev/ko/reference/errors/)

## 소스

커밋 af54ddad5의 규칙 원문:

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