implement: 제네릭 모노모피제이션 (SPEC 9)
타입 인자를 바인딩한 상태로 선언을 인스턴스마다 한 번씩 검사한다. 바인딩된 이름은 그냥 그 인자 타입이므로 본문, 필드 타입, 시그니처가 모두 같은 규칙으로 풀린다. 인스턴스 정체성은 선언 유닛 + 선언 + 인자 철자다. 찾은 버그 셋: - 파서가 comptime 파라미터의 이름을 'comptime' 이라는 키워드에서 가져갔다. 타입 파라미터 이름이 전부 comptime 이 되어 아무것도 바인딩되지 않았다. - 인스턴스 이름이 중첩마다 길어져서, 깊은 사슬에서 잘린 이름끼리 충돌해 재귀가 깊이 제한에 닿기 전에 조용히 멈췄다. 길어지면 인자를 일련번호로 적어 정체성을 유지한다. - 순서 비교 연산자가 피연산자 타입을 보지 않아 구조체끼리 비교해도 통과했다. 제네릭과 무관한 기존 구멍이다. fixture 셋이 명세와 어긋나 있어 명세를 따랐다. badbody 와 badop 은 호출 지점을 primary error 로 기대했지만 SPEC 9 는 본문의 연산이 primary 이고 호출에는 'instantiated here' note 를 붙이라고 한다. okscope 는 제네릭 본문이 호출자의 이름을 본다고 기대했지만 SPEC 9 는 정의 유닛에서 해석한다 -- badscope 로 옮기고 이유를 적었다. 188/188.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
// ERROR:9:instantiation
|
||||
// ERROR:7:arithmetic operands
|
||||
// SPEC 9: the defect is the operation in the body, so that is the primary
|
||||
// error; the call gets an `instantiated here` note.
|
||||
unit badbody;
|
||||
|
||||
fn add(comptime T: type, a: T, b: T) -> T {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// ERROR:16:instantiation
|
||||
// ERROR:11:ordering requires
|
||||
// SPEC 9: the primary error is the comparison in the body. The call at the
|
||||
// bottom gets an `instantiated here` note.
|
||||
unit badop;
|
||||
|
||||
struct Token {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// ERROR:unknown function
|
||||
// SPEC 9: a generic body resolves its names in the unit that declared it,
|
||||
// so lib.call cannot see this unit's `helper`. The mirror of defscope/,
|
||||
// where the definition unit's own private helper is reachable.
|
||||
unit main;
|
||||
import lib;
|
||||
|
||||
fn helper(v: i32) -> i32 { return v + 10; }
|
||||
|
||||
fn main() -> i32 {
|
||||
return lib.call(i32, 1);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
unit main;
|
||||
import lib;
|
||||
|
||||
fn helper(v: i32) -> i32 { return v + 10; }
|
||||
|
||||
fn main() -> i32 {
|
||||
return lib.call(i32, 1);
|
||||
}
|
||||
Reference in New Issue
Block a user