---
title: "TS8031 RECURSION: TypeShade 컴파일러가 진단에 붙이는 오류 코드와 그 뜻, 고치는 법"
description: "TS8031 RECURSION, TypeShade 컴파일러의 오류 코드입니다. 호출 순환입니다. 함수가 직접, 또는 다른 함수를 거쳐 자기 자신에 닿습니다. WGSL에는 호출 스택이 없으므로 컴파일러가 타깃이 보기 전에 순환을 거부합니다."
url: https://typeshade.dev/ko/reference/errors/ts8031/
language: ko
---

# `TS8031`

프런트엔드 코드 `RECURSION`

호출 순환입니다. 함수가 직접, 또는 다른 함수를 거쳐 자기 자신에 닿습니다. WGSL에는 호출 스택이 없으므로 컴파일러가 타깃이 보기 전에 순환을 거부합니다.

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

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

## 예제

example.shade.ts

```ts
"use typeshade"

function fold(x: f32): f32 {
  if (x < 1.) {
    return x
  }
  return fold(x * 0.5)
}

@fragment
export function main(uv: location<0, vec2>): vec4 {
  return vec4(uv, fold(uv.x * 8.), 1.)
}
```

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

**TS8031** error, 7행: Recursive call: "fold" -> "fold". WGSL has no call stack, so a function must not take part in a call cycle.

## 고치는 법

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

example.shade.ts

```ts
"use typeshade"

function fold(x: f32): f32 {
  let y = x
  for (let i = 0; i < 8; i++) {
    if (y < 1.) {
      break
    }
    y = y * 0.5
  }
  return y
}

@fragment
export function main(uv: location<0, vec2>): vec4 {
  return vec4(uv, fold(uv.x * 8.), 1.)
}
```

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

**[규칙 8.4](https://typeshade.dev/ko/reference/rules/8-4/) 테스트**

A function must not take part in a call cycle, directly or through other functions; the check reads the calls a body writes, and the calls a method call, an accessor and `new` lower to, before any optimisation, so a call in a branch the optimizer would drop is a cycle too.

**[규칙 8.18](https://typeshade.dev/ko/reference/rules/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](https://typeshade.dev/ko/reference/rules/8-16/)) and a local function ([Rule 8.17](https://typeshade.dev/ko/reference/rules/8-17/)).

**[규칙 8.19](https://typeshade.dev/ko/reference/rules/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](https://typeshade.dev/ko/reference/rules/8-17/)), each instance of a generic function ([Rule 8.9](https://typeshade.dev/ko/reference/rules/8-9/)) and of a function that takes a function ([Rule 8.18](https://typeshade.dev/ko/reference/rules/8-18/)), a method, a getter and a field that holds a function ([Rule 8.16](https://typeshade.dev/ko/reference/rules/8-16/)) take the type of their first `return` with a value, the `return`s after it are typed against that type as against a written one, and one with no such `return` returns nothing.

**[규칙 12.6](https://typeshade.dev/ko/reference/rules/12-6/) 테스트**

A requirement the front end can check must be checked at the front end, in the author’s words, and not left to Tint or a driver.

## 함께 보기

- [함수](https://typeshade.dev/ko/guide/language/functions/)
- [오류 코드](https://typeshade.dev/ko/reference/errors/)

## 소스

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

- [`src/compiler/ts/lower/function.ts:606`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/function.ts#L606) (4곳)
- [`src/compiler/ts/recursion.ts:146`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/recursion.ts#L146) (2곳)
- [`src/language-service/diagnostics.ts:112`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/diagnostics.ts#L112)
