Skip to content

Commit ef81146

Browse files
Omnibus cleanup from o1-mini's syntactic code review (microsoft#341)
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
1 parent a63bfea commit ef81146

File tree

19 files changed

+63
-61
lines changed

19 files changed

+63
-61
lines changed

internal/ast/ast.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func (n *Node) TypeParameterList() *NodeList {
356356
return funcLike.TypeParameters
357357
}
358358
}
359-
panic("Unhandled case in Node.TypeParameters")
359+
panic("Unhandled case in Node.TypeParameterList")
360360
}
361361

362362
func (n *Node) TypeParameters() []*Node {
@@ -382,7 +382,7 @@ func (n *Node) MemberList() *NodeList {
382382
case KindMappedType:
383383
return n.AsMappedTypeNode().Members
384384
}
385-
panic("Unhandled case in Node.Members")
385+
panic("Unhandled case in Node.MemberList")
386386
}
387387

388388
func (n *Node) Members() []*Node {
@@ -7596,12 +7596,12 @@ type Pragma struct {
75967596
type PragmaKindFlags = uint8
75977597

75987598
const (
7599-
PragmaKindFlagsNone PragmaKindFlags = iota
7600-
PragmaKindTripleSlashXML
7599+
PragmaKindTripleSlashXML PragmaKindFlags = 1 << iota
76017600
PragmaKindSingleLine
76027601
PragmaKindMultiLine
7603-
PragmaKindAll = PragmaKindTripleSlashXML | PragmaKindSingleLine | PragmaKindMultiLine
7604-
PragmaKindDefault = PragmaKindAll
7602+
PragmaKindFlagsNone PragmaKindFlags = 0
7603+
PragmaKindAll = PragmaKindTripleSlashXML | PragmaKindSingleLine | PragmaKindMultiLine
7604+
PragmaKindDefault = PragmaKindAll
76057605
)
76067606

76077607
type PragmaArgumentSpecification struct {

internal/checker/checker.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,15 +2444,15 @@ func (c *Checker) checkObjectTypeForDuplicateDeclarations(node *ast.Node, checkP
24442444
if len(symbol.Declarations) > 1 {
24452445
var names map[string]int
24462446
if isStatic {
2447-
if instanceNames == nil {
2448-
instanceNames = make(map[string]int)
2449-
}
2450-
names = instanceNames
2451-
} else {
24522447
if staticNames == nil {
24532448
staticNames = make(map[string]int)
24542449
}
24552450
names = staticNames
2451+
} else {
2452+
if instanceNames == nil {
2453+
instanceNames = make(map[string]int)
2454+
}
2455+
names = instanceNames
24562456
}
24572457
if state := names[symbol.Name]; state != 2 {
24582458
if state == 1 {
@@ -4953,7 +4953,7 @@ func (iterationTypes *IterationTypes) getType(typeKind IterationTypeKind) *Type
49534953
case IterationTypeKindNext:
49544954
return iterationTypes.nextType
49554955
}
4956-
panic("Unhandled case in getIterationTypeOfIterable")
4956+
panic("Unhandled case in getType(IterationTypeKind)")
49574957
}
49584958

49594959
func (c *Checker) combineIterationTypes(iterationTypes []IterationTypes) IterationTypes {
@@ -7834,7 +7834,7 @@ func (c *Checker) isPromiseResolveArityError(node *ast.Node) bool {
78347834

78357835
func getErrorNodeForCallNode(node *ast.Node) *ast.Node {
78367836
if ast.IsCallExpression(node) {
7837-
node := node.Expression()
7837+
node = node.Expression()
78387838
if ast.IsPropertyAccessExpression(node) {
78397839
node = node.Name()
78407840
}
@@ -12429,6 +12429,7 @@ func (c *Checker) markSymbolOfAliasDeclarationIfTypeOnly(aliasDeclaration *ast.N
1242912429
}
1243012430

1243112431
func (c *Checker) markSymbolOfAliasDeclarationIfTypeOnlyWorker(aliasDeclarationLinks *AliasSymbolLinks, target *ast.Symbol, overwriteEmpty bool) bool {
12432+
// !!! following line checks aliasDeclarationLinks.typeOnlyDeclaration == nil twice; figure out what this was supposed to be
1243212433
if target != nil && (aliasDeclarationLinks.typeOnlyDeclaration == nil || overwriteEmpty && aliasDeclarationLinks.typeOnlyDeclarationResolved && aliasDeclarationLinks.typeOnlyDeclaration == nil) {
1243312434
exportSymbol := target.Exports[ast.InternalSymbolNameExportEquals]
1243412435
if exportSymbol == nil {
@@ -12994,7 +12995,7 @@ func (c *Checker) addDeclarationToLateBoundSymbol(symbol *ast.Symbol, member *as
1299412995
*/
1299512996
func (c *Checker) getMembersOfSymbol(symbol *ast.Symbol) ast.SymbolTable {
1299612997
if symbol.Flags&ast.SymbolFlagsLateBindingContainer != 0 {
12997-
return c.getResolvedMembersOrExportsOfSymbol(symbol, MembersOrExportsResolutionKindresolvedMembers)
12998+
return c.getResolvedMembersOrExportsOfSymbol(symbol, MembersOrExportsResolutionKindResolvedMembers)
1299812999
}
1299913000
return symbol.Members
1300013001
}
@@ -14315,7 +14316,7 @@ func getUnionKey(types []*Type, origin *Type, alias *TypeAlias) string {
1431514316
b.WriteByte('|')
1431614317
b.WriteTypes(types)
1431714318
default:
14318-
panic("Unhandled case in getUnionId")
14319+
panic("Unhandled case in getUnionKey")
1431914320
}
1432014321
b.WriteAlias(alias)
1432114322
return b.String()
@@ -17869,7 +17870,7 @@ func (c *Checker) resolveIntersectionTypeMembers(t *Type) {
1786917870
func (c *Checker) appendSignatures(signatures []*Signature, newSignatures []*Signature) []*Signature {
1787017871
for _, sig := range newSignatures {
1787117872
if len(signatures) == 0 || core.Every(signatures, func(s *Signature) bool {
17872-
return c.compareSignaturesIdentical(s, sig, false /*partialMatch*/, false /*ignoreThisTypes*/, false /*ignoreReturnTypes*/, c.compareTypesIdentical) == 0
17873+
return c.compareSignaturesIdentical(s, sig, false /*partialMatch*/, false /*ignoreThisTypes*/, false /*ignoreReturnTypes*/, c.compareTypesIdentical) == TernaryFalse
1787317874
}) {
1787417875
signatures = append(signatures, sig)
1787517876
}

internal/checker/relater.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ func (c *Checker) checkTypeRelatedToEx(
402402
}
403403

404404
func createDiagnosticChainFromErrorChain(chain *ErrorChain, errorNode *ast.Node, relatedInfo []*ast.Diagnostic) *ast.Diagnostic {
405-
for chain != nil && chain.message.ElidedInCompatabilityPyramid() {
405+
for chain != nil && chain.message.ElidedInCompatibilityPyramid() {
406406
chain = chain.next
407407
}
408408
if chain == nil {

internal/checker/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ type MembersOrExportsResolutionKind int
193193

194194
const (
195195
MembersOrExportsResolutionKindResolvedExports MembersOrExportsResolutionKind = 0
196-
MembersOrExportsResolutionKindresolvedMembers MembersOrExportsResolutionKind = 1
196+
MembersOrExportsResolutionKindResolvedMembers MembersOrExportsResolutionKind = 1
197197
)
198198

199199
type MembersAndExportsLinks [2]ast.SymbolTable // Indexed by MembersOrExportsResolutionKind
200200

201-
// Links for syntheric spread properties
201+
// Links for synthetic spread properties
202202

203203
type SpreadLinks struct {
204204
leftSpread *ast.Symbol // Left source for synthetic spread property

internal/compiler/diagnostics/diagnostics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type Message struct {
3535
key string
3636
text string
3737
reportsUnnecessary bool
38-
elidedInCompatabilityPyramid bool
38+
elidedInCompatibilityPyramid bool
3939
reportsDeprecated bool
4040
}
4141

@@ -44,7 +44,7 @@ func (m *Message) Category() Category { return m.category }
4444
func (m *Message) Key() string { return m.key }
4545
func (m *Message) Message() string { return m.text }
4646
func (m *Message) ReportsUnnecessary() bool { return m.reportsUnnecessary }
47-
func (m *Message) ElidedInCompatabilityPyramid() bool { return m.elidedInCompatabilityPyramid }
47+
func (m *Message) ElidedInCompatibilityPyramid() bool { return m.elidedInCompatibilityPyramid }
4848
func (m *Message) ReportsDeprecated() bool { return m.reportsDeprecated }
4949

5050
func (m *Message) Format(args ...any) string {

internal/compiler/diagnostics/diagnostics_generated.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/compiler/diagnostics/generate.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ import (
2323
)
2424

2525
type diagnosticMessage struct {
26-
Category string `json:"category"`
27-
Code int `json:"code"`
28-
ReportsUnnecessary bool `json:"reportsUnnecessary"`
29-
ReportsDeprecated bool `json:"reportsDeprecated"`
30-
ElidedInCompatabilityPyramid bool `json:"elidedInCompatabilityPyramid"`
26+
Category string `json:"category"`
27+
Code int `json:"code"`
28+
ReportsUnnecessary bool `json:"reportsUnnecessary"`
29+
ReportsDeprecated bool `json:"reportsDeprecated"`
30+
// spelling error here is [sic] in Strada
31+
ElidedInCompatibilityPyramid bool `json:"elidedInCompatabilityPyramid"`
3132

3233
key string
3334
}
@@ -86,8 +87,8 @@ func main() {
8687
if m.ReportsUnnecessary {
8788
buf.WriteString(`, reportsUnnecessary: true`)
8889
}
89-
if m.ElidedInCompatabilityPyramid {
90-
buf.WriteString(`, elidedInCompatabilityPyramid: true`)
90+
if m.ElidedInCompatibilityPyramid {
91+
buf.WriteString(`, elidedInCompatibilityPyramid: true`)
9192
}
9293
if m.ReportsDeprecated {
9394
buf.WriteString(`, reportsDeprecated: true`)

internal/compiler/program.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func getModuleNames(file *ast.SourceFile) []*ast.Node {
256256
}
257257

258258
func (p *Program) GetSyntacticDiagnostics(sourceFile *ast.SourceFile) []*ast.Diagnostic {
259-
return p.getDiagnosticsHelper(sourceFile, false /*ensureBound*/, false /*ensureChecked*/, p.getSyntaticDiagnosticsForFile)
259+
return p.getDiagnosticsHelper(sourceFile, false /*ensureBound*/, false /*ensureChecked*/, p.getSyntacticDiagnosticsForFile)
260260
}
261261

262262
func (p *Program) GetBindDiagnostics(sourceFile *ast.SourceFile) []*ast.Diagnostic {
@@ -288,7 +288,7 @@ func (p *Program) getOptionsDiagnosticsOfConfigFile() []*ast.Diagnostic {
288288
return p.configFileParsingDiagnostics // TODO: actually call getDiagnosticsHelper on config path
289289
}
290290

291-
func (p *Program) getSyntaticDiagnosticsForFile(sourceFile *ast.SourceFile) []*ast.Diagnostic {
291+
func (p *Program) getSyntacticDiagnosticsForFile(sourceFile *ast.SourceFile) []*ast.Diagnostic {
292292
return sourceFile.Diagnostics()
293293
}
294294

internal/jsnum/jsnum_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ func TestBitwiseNOT(t *testing.T) {
115115
}{
116116
{-2147483649, Number(2147483647).BitwiseNOT()},
117117
{-4294967296, Number(0).BitwiseNOT()},
118-
{-2147483648, Number(-2147483648).BitwiseNOT()},
119-
{-4294967296, Number(0).BitwiseNOT()},
118+
{2147483648, Number(-2147483648).BitwiseNOT()},
119+
{4294967296, Number(0).BitwiseNOT()},
120120
}
121121

122122
for _, test := range tests {

internal/printer/namegenerator_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ func TestUniqueName2(t *testing.T) {
188188
text2 := g.GenerateName(name1)
189189

190190
assert.Equal(t, "foo_1", text1)
191+
// Expected to be same because GenerateName goes off object identity
191192
assert.Equal(t, "foo_1", text2)
192193
}
193194

0 commit comments

Comments
 (0)