Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type substitution within parameterized type names #880

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
l46kok marked this conversation as resolved.
Show resolved Hide resolved
// 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