---
title: "TS8006 LOOP_BOUND: TypeShade 컴파일러가 진단에 붙이는 오류 코드와 그 뜻, 고치는 법"
description: "TS8006 LOOP_BOUND, TypeShade 컴파일러의 오류 코드입니다. 컴파일러가 조건을 받아들이지 않는 루프입니다."
url: https://typeshade.dev/ko/reference/errors/ts8006/
language: ko
---

# `TS8006`

프런트엔드 코드 `LOOP_BOUND`

컴파일러가 조건을 받아들이지 않는 루프입니다. 시작값, 경계, 증분이 모두 상수인 `for`에서 조건이 거짓이 되기 전에 카운터가 타입의 범위를 벗어나거나, 루프 조건 안에서 값을 쓰는 함수를 호출합니다. 이름이 아닌 배열을 도는 `for...of`도 이 코드로 거부됩니다.

레지스트리에는 이 상수에 대한 문서 주석이 없습니다. 그래서 위 설명은 컴파일러가 이 코드와 함께 내는 메시지를 보고 이 사이트가 쓴 것입니다.

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

## 예제

example.shade.ts

```ts
"use typeshade"

@fragment
export function main(uv: location<0, vec2>): vec4 {
  let g = 0.
  for (let i: u32 = 0; i <= 4294967295; i++) {
    g += 0.1
  }
  return vec4(g, g, g, 1.)
}
```

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

**TS8006** error, 6행: for (i = 0; i <= 4294967295; i += 1) walks "i" outside the range of `u32` before the condition fails.

## 고치는 법

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

example.shade.ts

```ts
"use typeshade"

@fragment
export function main(uv: location<0, vec2>): vec4 {
  let g = 0.
  for (let i: u32 = 0; i < 4294967295; i++) {
    g += 0.1
  }
  return vec4(g, g, g, 1.)
}
```

## 이 코드가 적용하는 규칙

**[규칙 7.5](https://typeshade.dev/ko/reference/rules/7-5/) 테스트**

A `for` loop means what it means in TypeScript: its initializer runs once, its condition (`true` when it has none) is tested before each trip, and its update runs after each trip and at each `continue` (change 0136).

**[규칙 7.9](https://typeshade.dev/ko/reference/rules/7-9/) 테스트**

An expression must be evaluated left to right, as TypeScript and WGSL both evaluate it, and a call that writes (its object, a module variable, a storage binding, an atomic location) inside a larger expression must take effect in that order on every target.

## 함께 보기

- [제어 흐름](https://typeshade.dev/ko/guide/language/control-flow/)
- [오류 코드](https://typeshade.dev/ko/reference/errors/)

## 소스

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

- [`src/compiler/ts/loop-bound/counted-for.ts:71`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/loop-bound/counted-for.ts#L71) (4곳)
- [`src/compiler/ts/lower/control/for-of.ts:72`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/control/for-of.ts#L72) (2곳)
- [`src/compiler/ts/sequence.ts:573`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/sequence.ts#L573)
