mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 18:58:30 +00:00
fix: dict subtyping bug
This commit is contained in:
parent
ae9648b289
commit
c181fc4ff6
2 changed files with 11 additions and 3 deletions
|
@ -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 {
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue