Skip to content

Commit 6524ca6

Browse files
authored
Reset member resolution after base type resolution (#1779)
1 parent 414c04e commit 6524ca6

7 files changed

+15
-63
lines changed

internal/checker/checker.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18332,6 +18332,11 @@ func (c *Checker) getBaseTypes(t *Type) []*Type {
1833218332
}
1833318333
}
1833418334
}
18335+
// In general, base type resolution always precedes member resolution. However, it is possible
18336+
// for resolution of type parameter defaults to cause circularity errors, possibly leaving
18337+
// members partially resolved. Here we ensure any such partial resolution is reset.
18338+
// See https://github.com/microsoft/TypeScript/issues/16861 for an example.
18339+
t.objectFlags &^= ObjectFlagsMembersResolved
1833518340
data.baseTypesResolved = true
1833618341
}
1833718342
return data.resolvedBaseTypes
@@ -18395,14 +18400,6 @@ func (c *Checker) resolveBaseTypesOfClass(t *Type) {
1839518400
c.error(t.symbol.ValueDeclaration, diagnostics.Type_0_recursively_references_itself_as_a_base_type, c.TypeToString(t))
1839618401
return
1839718402
}
18398-
// !!! This logic is suspicious. We really shouldn't be un-resolving members after they've been resolved.
18399-
// if t.resolvedBaseTypes == resolvingEmptyArray {
18400-
// // Circular reference, likely through instantiation of default parameters
18401-
// // (otherwise there'd be an error from hasBaseType) - this is fine, but `.members` should be reset
18402-
// // as `getIndexedAccessType` via `instantiateType` via `getTypeFromClassOrInterfaceReference` forces a
18403-
// // partial instantiation of the members without the base types fully resolved
18404-
// t.members = nil
18405-
// }
1840618403
t.AsInterfaceType().resolvedBaseTypes = []*Type{reducedBaseType}
1840718404
}
1840818405

testdata/baselines/reference/submodule/compiler/circularConstraintYieldsAppropriateError.errors.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
circularConstraintYieldsAppropriateError.ts(10,7): error TS2310: Type 'Foo' recursively references itself as a base type.
2-
circularConstraintYieldsAppropriateError.ts(17,5): error TS2339: Property 'bar' does not exist on type 'Foo'.
32

43

5-
==== circularConstraintYieldsAppropriateError.ts (2 errors) ====
4+
==== circularConstraintYieldsAppropriateError.ts (1 errors) ====
65
// https://github.com/Microsoft/TypeScript/issues/16861
76
class BaseType<T> {
87
bar: T
@@ -21,6 +20,4 @@ circularConstraintYieldsAppropriateError.ts(17,5): error TS2339: Property 'bar'
2120
}
2221

2322
const foo = new Foo();
24-
foo.bar.test
25-
~~~
26-
!!! error TS2339: Property 'bar' does not exist on type 'Foo'.
23+
foo.bar.test

testdata/baselines/reference/submodule/compiler/circularConstraintYieldsAppropriateError.errors.txt.diff

Lines changed: 0 additions & 20 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/circularConstraintYieldsAppropriateError.symbols

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,9 @@ const foo = new Foo();
4242
>Foo : Symbol(Foo, Decl(circularConstraintYieldsAppropriateError.ts, 7, 1))
4343

4444
foo.bar.test
45+
>foo.bar.test : Symbol(test, Decl(circularConstraintYieldsAppropriateError.ts, 10, 15))
46+
>foo.bar : Symbol(BaseType.bar, Decl(circularConstraintYieldsAppropriateError.ts, 1, 19))
4547
>foo : Symbol(foo, Decl(circularConstraintYieldsAppropriateError.ts, 15, 5))
48+
>bar : Symbol(BaseType.bar, Decl(circularConstraintYieldsAppropriateError.ts, 1, 19))
49+
>test : Symbol(test, Decl(circularConstraintYieldsAppropriateError.ts, 10, 15))
4650

testdata/baselines/reference/submodule/compiler/circularConstraintYieldsAppropriateError.symbols.diff

Lines changed: 0 additions & 11 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/circularConstraintYieldsAppropriateError.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ const foo = new Foo();
3737
>Foo : typeof Foo
3838

3939
foo.bar.test
40-
>foo.bar.test : any
41-
>foo.bar : any
40+
>foo.bar.test : true
41+
>foo.bar : { test: true; }
4242
>foo : Foo
43-
>bar : any
44-
>test : any
43+
>bar : { test: true; }
44+
>test : true
4545

testdata/baselines/reference/submodule/compiler/circularConstraintYieldsAppropriateError.types.diff

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)