diff --git a/midas/checker/types.py b/midas/checker/types.py index 708d68b..c9667e5 100644 --- a/midas/checker/types.py +++ b/midas/checker/types.py @@ -140,6 +140,9 @@ def substitute_typevars(type: Type, substitutions: dict[str, Type]) -> Type: ) match type: + case TopType(): + return type + case BaseType(name=name) if name in substitutions: return substitutions[name] @@ -200,6 +203,21 @@ def substitute_typevars(type: Type, substitutions: dict[str, Type]) -> Type: return substitutions[name] raise ValueError(f"Missing TypeVar substitution for {name}") + case GenericType(name=name, params=params, body=body): + params2: list[TypeVar] = [] + for param in params: + param2: Type = substitute_typevars(param, substitutions) + if not isinstance(param2, TypeVar): + raise ValueError( + f"Invalid type parameter substitution, expected TypeVar, got {param2}" + ) + params2.append(param2) + return GenericType( + name=name, + params=params2, + body=substitute_typevars(body, substitutions), + ) + case UnknownType() | UnitType(): return type