Skip to content

Commit

Permalink
Fix type substitution within parameterized type names (#880)
Browse files Browse the repository at this point in the history
  • Loading branch information
TristonianJones authored Jan 8, 2024
1 parent d45f67f commit b7269b1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
29 changes: 29 additions & 0 deletions checker/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2233,6 +2233,35 @@ _&&_(_==_(list~type(list(dyn))^list,
| NotAMessage{}
| ...........^`,
},
{
in: `{}.map(c,[c,type(c)])`,
out: `__comprehension__(
// Variable
c,
// Target
{}~map(dyn, dyn),
// Accumulator
__result__,
// Init
[]~list(list(dyn)),
// LoopCondition
true~bool,
// LoopStep
_+_(
__result__~list(list(dyn))^__result__,
[
[
c~dyn^c,
type(
c~dyn^c
)~type(dyn)^type
]~list(dyn)
]~list(list(dyn))
)~list(list(dyn))^add_list,
// Result
__result__~list(list(dyn))^__result__)~list(list(dyn))`,
outType: types.NewListType(types.NewListType(types.DynType)),
},
}
}

Expand Down
5 changes: 3 additions & 2 deletions checker/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func notReferencedIn(m *mapping, t, withinType *types.Type) bool {
return true
}
return notReferencedIn(m, t, wtSub)
case types.OpaqueKind, types.ListKind, types.MapKind:
case types.OpaqueKind, types.ListKind, types.MapKind, types.TypeKind:
for _, pt := range withinType.Parameters() {
if !notReferencedIn(m, t, pt) {
return false
Expand Down Expand Up @@ -292,7 +292,8 @@ func substitute(m *mapping, t *types.Type, typeParamToDyn bool) *types.Type {
substitute(m, t.Parameters()[1], typeParamToDyn))
case types.TypeKind:
if len(t.Parameters()) > 0 {
return types.NewTypeTypeWithParam(substitute(m, t.Parameters()[0], typeParamToDyn))
tParam := t.Parameters()[0]
return types.NewTypeTypeWithParam(substitute(m, tParam, typeParamToDyn))
}
return t
default:
Expand Down

0 comments on commit b7269b1

Please sign in to comment.