Skip to content

Commit 775bdc7

Browse files
committed
sem/eval: fix TestCastMap properly for AnyTuple
`TestCastMap` iterates over `types.OidToType` map to find all interesting pairs to perform the cast between. One of the representative types in the map is `types.AnyTuple` that is actually not a valid execution-time type (it's a wildcard used only during static analysis). Previously we could crash in the test if we happen to pick a float value as the element corresponding to the single Any type element (because float width is 0 there). This commit fixes the test by effectively "resolving" `AnyTuple` type to a concrete tuple type with a single random type as the element. Release note: None
1 parent 45e8f5c commit 775bdc7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pkg/sql/sem/eval/cast_map_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ func TestCastMap(t *testing.T) {
3838

3939
cast.ForEachCast(func(src, tgt oid.Oid, _ cast.Context, _ cast.ContextOrigin, _ volatility.V) {
4040
srcType := types.OidToType[src]
41+
if srcType.Oid() == oid.T_record {
42+
// We're looking at the types.AnyTuple that is a wildcard that
43+
// cannot be used during execution. In order to make it a valid
44+
// execution type, we construct an equivalent with the tuple element
45+
// resolved to a random type.
46+
var emptyLocale = ""
47+
srcType = &types.T{
48+
InternalType: types.InternalType{
49+
Family: types.TupleFamily,
50+
TupleContents: []*types.T{randgen.RandType(rng)},
51+
Oid: oid.T_record,
52+
Locale: &emptyLocale,
53+
},
54+
}
55+
}
4156
tgtType := types.OidToType[tgt]
4257
srcDatum := randgen.RandDatum(rng, srcType, false /* nullOk */)
4358

0 commit comments

Comments
 (0)