Skip to content

compareTypes2(t1, t2) does not always equal -compareTypes2(t2, t1) #1839

@jakebailey

Description

@jakebailey

Replace CompareTypes with:

func CompareTypes(t1, t2 *Type) int {
	return -compareTypes2(t2, t1)
}

func compareTypes2(t1, t2 *Type) int {
	if t1 == t2 {
		return 0
	}
	// ...

And then tests say:

✖  internal/testrunner (12.194s)

=== Failed
=== FAIL: internal/testrunner TestSubmodule/dynamicImportsDeclaration.ts/output (0.01s)
    baseline.go:202: the baseline file /home/jabaile/work/TypeScript-go/testdata/baselines/reference/submodule/compiler/dynamicImportsDeclaration.js has changed. (Run `hereby baseline-accept` if the new baseline is correct.)
    baseline.go:202: the baseline file /home/jabaile/work/TypeScript-go/testdata/baselines/reference/submodule/compiler/dynamicImportsDeclaration.js.diff has changed. (Run `hereby baseline-accept` if the new baseline is correct.)

=== FAIL: internal/testrunner TestSubmodule/dynamicImportsDeclaration.ts/type (0.00s)
    baseline.go:202: the baseline file /home/jabaile/work/TypeScript-go/testdata/baselines/reference/submodule/compiler/dynamicImportsDeclaration.types has changed. (Run `hereby baseline-accept` if the new baseline is correct.)
    baseline.go:197: new baseline created at /home/jabaile/work/TypeScript-go/testdata/baselines/local/submodule/compiler/dynamicImportsDeclaration.types.diff.

=== FAIL: internal/testrunner TestSubmodule/dynamicImportsDeclaration.ts (0.01s)

=== FAIL: internal/testrunner TestSubmodule/instantiationExpressions.ts/type (0.01s)
    baseline.go:202: the baseline file /home/jabaile/work/TypeScript-go/testdata/baselines/reference/submodule/conformance/instantiationExpressions.types has changed. (Run `hereby baseline-accept` if the new baseline is correct.)
    baseline.go:202: the baseline file /home/jabaile/work/TypeScript-go/testdata/baselines/reference/submodule/conformance/instantiationExpressions.types.diff has changed. (Run `hereby baseline-accept` if the new baseline is correct.)

=== FAIL: internal/testrunner TestSubmodule/instantiationExpressions.ts (0.17s)

=== FAIL: internal/testrunner TestSubmodule (1.16s)

So, there's something not quite right in the type comparison algorithm.

Noticed this while trying to cache these comparisons in Strada's version of this (doing the common trick of using a canonical ordering for the cache key to halve its size).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions