Skip to content

Commit e7a30f5

Browse files
authored
Ensure we don't copy OrderedMaps (#1003)
1 parent b53f521 commit e7a30f5

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

internal/checker/checker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20072,7 +20072,7 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s
2007220072
if singleProp == nil || isUnion &&
2007320073
(propSet.Size() != 0 || checkFlags&ast.CheckFlagsPartial != 0) &&
2007420074
checkFlags&(ast.CheckFlagsContainsPrivate|ast.CheckFlagsContainsProtected) != 0 &&
20075-
!(propSet.Size() != 0 && c.hasCommonDeclaration(propSet)) {
20075+
!(propSet.Size() != 0 && c.hasCommonDeclaration(&propSet)) {
2007620076
// No property was found, or, in a union, a property has a private or protected declaration in one
2007720077
// constituent, but is missing or has a different declaration in another constituent.
2007820078
return nil
@@ -20194,7 +20194,7 @@ func isPrototypeProperty(symbol *ast.Symbol) bool {
2019420194
return symbol.Flags&ast.SymbolFlagsMethod != 0 || symbol.CheckFlags&ast.CheckFlagsSyntheticMethod != 0
2019520195
}
2019620196

20197-
func (c *Checker) hasCommonDeclaration(symbols collections.OrderedSet[*ast.Symbol]) bool {
20197+
func (c *Checker) hasCommonDeclaration(symbols *collections.OrderedSet[*ast.Symbol]) bool {
2019820198
var commonDeclarations core.Set[*ast.Node]
2019920199
for symbol := range symbols.Values() {
2020020200
if len(symbol.Declarations) == 0 {

internal/collections/ordered_map.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,22 @@ import (
1818

1919
// OrderedMap is an insertion ordered map.
2020
type OrderedMap[K comparable, V any] struct {
21+
_ noCopy
2122
keys []K
2223
mp map[K]V
2324
}
2425

26+
// noCopy may be embedded into structs which must not be copied
27+
// after the first use.
28+
//
29+
// See https://golang.org/issues/8005#issuecomment-190753527
30+
// for details.
31+
type noCopy struct{}
32+
33+
// Lock is a no-op used by -copylocks checker from `go vet`.
34+
func (*noCopy) Lock() {}
35+
func (*noCopy) Unlock() {}
36+
2537
// NewOrderedMapWithSizeHint creates a new OrderedMap with a hint for the number of elements it will contain.
2638
func NewOrderedMapWithSizeHint[K comparable, V any](hint int) *OrderedMap[K, V] {
2739
m := newMapWithSizeHint[K, V](hint)
@@ -191,7 +203,7 @@ func (m *OrderedMap[K, V]) clone() OrderedMap[K, V] {
191203
}
192204
}
193205

194-
func (m OrderedMap[K, V]) MarshalJSON() ([]byte, error) {
206+
func (m *OrderedMap[K, V]) MarshalJSON() ([]byte, error) {
195207
if len(m.mp) == 0 {
196208
return []byte("{}"), nil
197209
}

internal/tsoptions/tsconfigparsing.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ func hasFileWithHigherPriorityExtension(file string, extensions [][]string, hasF
14711471

14721472
// Removes files included via wildcard expansion with a lower extension priority that have already been included.
14731473
// file is the path to the file.
1474-
func removeWildcardFilesWithLowerPriorityExtension(file string, wildcardFiles collections.OrderedMap[string, string], extensions [][]string, keyMapper func(value string) string) {
1474+
func removeWildcardFilesWithLowerPriorityExtension(file string, wildcardFiles *collections.OrderedMap[string, string], extensions [][]string, keyMapper func(value string) string) {
14751475
var extensionGroup []string
14761476
for _, group := range extensions {
14771477
if tspath.FileExtensionIsOneOf(file, group) {
@@ -1575,7 +1575,7 @@ func getFileNamesFromConfigSpecs(
15751575
// extension due to the user-defined order of entries in the
15761576
// "include" array. If there is a lower priority extension in the
15771577
// same directory, we should remove it.
1578-
removeWildcardFilesWithLowerPriorityExtension(file, wildcardFileMap, supportedExtensions, keyMappper)
1578+
removeWildcardFilesWithLowerPriorityExtension(file, &wildcardFileMap, supportedExtensions, keyMappper)
15791579
key := keyMappper(file)
15801580
if !literalFileMap.Has(key) && !wildcardFileMap.Has(key) {
15811581
wildcardFileMap.Set(key, file)

0 commit comments

Comments
 (0)