규칙 8.10
이 페이지에서

규칙 8.10

8장, 함수와 진입점 테스트

A method that writes its object (assigns to this or to a field, a component or an element of it, applies ++ or -- to one, hands one to a parameter that its function writes (Rule 8.25), or calls such a method or reads such a getter on this, on a field, a component or an element of it whatever class that field is, or through super) must take the object by reference, and may return a value like any other method; a base’s body that a class calls through super and that writes its object takes it by reference too, and so does the copy of a method that takes a function (Rule 8.18) when a function handed over writes the variable the call is on. Its receiver must be a place a function may write: a let local, a const local whose initializer built its value or names a place (Rule 6.10), a module variable, a storage element, or this inside a constructor or another such method, or a field or an element of one of those. A receiver that is a parameter of a function of the file or of a namespace is the caller’s object (Rule 8.8); one that is a parameter of any other function, a const that holds a copy of an object something else may hold, or a value nothing holds must be refused with the remedy, as must a call of such a method that returns nothing where a value is expected. A method that only reads its object takes it as Rule 8.28 says: in place when the receiver is a place, and as a copy otherwise, so no receiver of one is refused. The same rule decides what a parameter that its function writes may be handed (Rule 8.25), and the object a call writes through counts as a reference in Rule 8.25’s check of one call. A method whose every return is return this returns its object, and a chain of calls on what it returns that is the whole of a call statement, of a declaration’s initializer or of a return (v.setX(1.).setY(2.)) must run each call but the last as a statement of its own, in source order, on the place the chain starts from, found once before the first call (an index it is reached through is read into a let), a new at the root being held in a temporary; inside a larger expression what such a method returns is a copy, and a call on it that writes its object must be refused with the remedy.

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

근거

WGSL takes a place as a pointer and GLSL ES 3.00 as an inout parameter, and either leaves the return free for a value, so a generator’s next() can advance its state and return the draw as TypeScript’s own method does; the rule that such a method returns nothing belonged to the protocol that returned the struct itself, which the reference replaced. A base’s body called through super changes the object of the body that called it, which hands its own reference on. A function handed to a method may write the very object the method runs on (this.each((i) => { this.total += … })), which in TypeScript is one object, so the copy takes it by the one reference both use. A field of this is part of this, so this.body.step(dt) writes this when step writes its object, whichever class declares step; before this a method that did so was refused as one that reads its object only. return this hands back the object, which a call inside a larger expression has no place to name: where a chain is the whole statement it can run on the place itself, which is TypeScript’s meaning, and where it is not, the copy is all there is, which is right for a read and wrong for a write.

출처

Reference and Pointer Types; Function Calls; GLSL ES 3.00 §6.1.1 (“Evaluation of an inout parameter results in both a value and an l-value”); ECMAScript the super keyword; surface §26 (design #86 step 2).

검증 방식

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

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

TS8035 CLASS_MEMBER for each refusal ("Gen.next" changes its object, and "r" is a const whose value may be one something else holds, which TypeScript would change with it and a copy here would not. Declare it with let to change a copy, or call it on the value itself.; "V.setY" changes its object, and inside this expression it would change the copy "v.setX(3.)" hands back. Make the chain a statement of its own, or call each method on the object itself.), pinned by src/compiler/ts/class-methods.test.ts and src/compiler/ts/class-syntax.test.ts, which also hold the three CPU paths to one value for a method that changes its object and returns one, a base’s body called through super that writes its object, a chain, and a method that writes its object through a field of another class, three levels deep; src/compiler/ts/higher-order.test.ts, which holds them to one value for the copy of a method whose function writes the object the call is on; src/compiler/ts/inout-params.test.ts; examples/gallery/orbit-inout/orbit-inout.shade.ts, examples/gallery/particle-step/particle-step.shade.ts, examples/gallery/rng-method/rng-method.shade.ts, examples/gallery/class-builder/class-builder.shade.ts and examples/gallery/class-parts/class-parts.shade.ts in the compile gate.

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

설명하는 절

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

적용하는 오류 코드

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

TS8035 CLASS_MEMBER
표면이 받지 않는 클래스 멤버 모양, 클래스 규칙이 거부하는 멤버 사용, 클래스를 만들지 않는 new입니다(규칙 8.13). getter와 setter, static 필드와 메서드, 오버로드 시그니처, abstract 멤버, # 비공개 이름, 객체를 바꾸는 메서드는 모두 컴파일됩니다. 메시지가 멤버나 대상과 고칠 방법을 알려 줍니다.

함께 보기

소스

커밋 af54ddad5의 규칙 원문:

이 페이지 편집 문제 보고