fix: dict subtyping bug

This commit is contained in:
Shunsuke Shibayama 2023-06-26 10:29:20 +09:00
parent ae9648b289
commit c181fc4ff6
2 changed files with 11 additions and 3 deletions

View file

@ -549,10 +549,12 @@ impl Context {
}
(Type, Poly { name, params }) if &name[..] == "Dict" => {
// Type :> Dict T == Type :> T
// e.g. Type :> Dict {Str: Int} == false
// e.g.
// Type :> Dict {"a": 1} == false
// Type :> Dict {Str: Int} == true
// Type :> Dict {Type: Type} == true
if let Ok(dict_t) = self.convert_tp_into_type(params[0].clone()) {
return self.supertype_of(&Type, &dict_t);
if let Ok(_dict_t) = self.convert_tp_into_type(params[0].clone()) {
return true;
}
// HACK: e.g. ?D: GenericDict
let Ok(dict) = Dict::try_from(params[0].clone()) else {

View file

@ -14,3 +14,9 @@ f(opt_i: Int or NoneType) =
log opt_i + 1 # ERR
f(1)
json = pyimport "json"
s = "{ \"key\": \"value\" }"
jdata = json.loads(s)
assert jdata in {Str: Str}
assert jdata["key"] == "value"