mirror of https://github.com/mtshiba/pylyzer
support type narrowing
This commit is contained in:
parent
9462b9572e
commit
6d4a791305
|
|
@ -252,8 +252,9 @@ checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
|
|||
|
||||
[[package]]
|
||||
name = "els"
|
||||
version = "0.1.21-nightly.0"
|
||||
source = "git+https://github.com/erg-lang/erg?branch=main#bf50ec289ab8c72f39fdb91cc4293af2133254e7"
|
||||
version = "0.1.21-nightly.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33ee5974e3be6b45da3325161134bd66301e6294c19a4ab9316ecd5075bb68c4"
|
||||
dependencies = [
|
||||
"erg_common",
|
||||
"erg_compiler",
|
||||
|
|
@ -273,8 +274,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "erg_common"
|
||||
version = "0.6.9-nightly.0"
|
||||
source = "git+https://github.com/erg-lang/erg?branch=main#bf50ec289ab8c72f39fdb91cc4293af2133254e7"
|
||||
version = "0.6.9-nightly.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd4554a4e4ff72596bbdc3765defe61cc9ac1a42ef591bd4a2d75d1b0019529e"
|
||||
dependencies = [
|
||||
"backtrace-on-stack-overflow",
|
||||
"hermit-abi",
|
||||
|
|
@ -284,8 +286,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "erg_compiler"
|
||||
version = "0.6.9-nightly.0"
|
||||
source = "git+https://github.com/erg-lang/erg?branch=main#bf50ec289ab8c72f39fdb91cc4293af2133254e7"
|
||||
version = "0.6.9-nightly.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6a7ba0ce5cb29487bca4f512b274719ca69a33b0806baff05a75cb38c70bc7d"
|
||||
dependencies = [
|
||||
"erg_common",
|
||||
"erg_parser",
|
||||
|
|
@ -293,8 +296,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "erg_parser"
|
||||
version = "0.6.9-nightly.0"
|
||||
source = "git+https://github.com/erg-lang/erg?branch=main#bf50ec289ab8c72f39fdb91cc4293af2133254e7"
|
||||
version = "0.6.9-nightly.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0a114df521d494e1b5fb650fed3186f722f196a4f048c33d7ddb1bb78064b51b"
|
||||
dependencies = [
|
||||
"erg_common",
|
||||
"unicode-xid 0.2.4",
|
||||
|
|
@ -589,9 +593,9 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.53"
|
||||
version = "1.0.54"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba466839c78239c09faf015484e5cc04860f88242cff4d03eb038f04b4699b73"
|
||||
checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
|
@ -759,9 +763,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.7.2"
|
||||
version = "1.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cce168fea28d3e05f158bda4576cf0c844d5045bc2cc3620fa0292ed5bb5814c"
|
||||
checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
|
|
@ -816,18 +820,18 @@ checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.158"
|
||||
version = "1.0.159"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9"
|
||||
checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.158"
|
||||
version = "1.0.159"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad"
|
||||
checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -836,9 +840,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.94"
|
||||
version = "1.0.95"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea"
|
||||
checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
|
|
@ -916,9 +920,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.8"
|
||||
version = "2.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bcc02725fd69ab9f26eab07fad303e2497fad6fb9eba4f96c4d1687bdf704ad9"
|
||||
checksum = "21e3787bb71465627110e7d87ed4faaa36c1f61042ee67badb9e2ef173accc40"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
|||
18
Cargo.toml
18
Cargo.toml
|
|
@ -22,16 +22,16 @@ edition = "2021"
|
|||
repository = "https://github.com/mtshiba/pylyzer"
|
||||
|
||||
[workspace.dependencies]
|
||||
# erg_common = { version = "0.6.9-nightly.0", features = ["py_compatible", "els"] }
|
||||
# erg_compiler = { version = "0.6.9-nightly.0", features = ["py_compatible", "els"] }
|
||||
# els = { version = "0.1.21-nightly.0", features = ["py_compatible"] }
|
||||
erg_common = { version = "0.6.9-nightly.2", features = ["py_compat", "els"] }
|
||||
erg_compiler = { version = "0.6.9-nightly.2", features = ["py_compat", "els"] }
|
||||
els = { version = "0.1.21-nightly.2", features = ["py_compat"] }
|
||||
rustpython-parser = "0.1.2"
|
||||
erg_compiler = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compatible", "els"] }
|
||||
erg_common = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compatible", "els"] }
|
||||
els = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compatible"] }
|
||||
# erg_compiler = { path = "../erg/crates/erg_compiler", features = ["py_compatible", "els"] }
|
||||
# erg_common = { path = "../erg/crates/erg_common", features = ["py_compatible", "els"] }
|
||||
# els = { path = "../erg/crates/els", features = ["py_compatible"] }
|
||||
# erg_compiler = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compat", "els"] }
|
||||
# erg_common = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compat", "els"] }
|
||||
# els = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compat"] }
|
||||
# erg_compiler = { path = "../erg/crates/erg_compiler", features = ["py_compat", "els"] }
|
||||
# erg_common = { path = "../erg/crates/erg_common", features = ["py_compat", "els"] }
|
||||
# els = { path = "../erg/crates/els", features = ["py_compat"] }
|
||||
|
||||
[features]
|
||||
debug = ["erg_compiler/debug", "erg_common/debug", "py2erg/debug"]
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ impl BlockKind {
|
|||
}
|
||||
}
|
||||
|
||||
/// Variables are automatically rewritten with `py_compatible`,
|
||||
/// Variables are automatically rewritten with `py_compat`,
|
||||
/// but types are rewritten here because they are complex components used inseparably in the Erg system.
|
||||
fn escape_name(name: String) -> String {
|
||||
match &name[..] {
|
||||
|
|
@ -544,6 +544,9 @@ impl ASTConverter {
|
|||
ExpressionType::Identifier { name } => TypeSpec::PreDeclTy(PreDeclTypeSpec::Simple(
|
||||
self.convert_ident_type_spec(name, expr.location),
|
||||
)),
|
||||
ExpressionType::None => TypeSpec::PreDeclTy(PreDeclTypeSpec::Simple(
|
||||
self.convert_ident_type_spec("NoneType".into(), expr.location),
|
||||
)),
|
||||
ExpressionType::Attribute { value, name } => {
|
||||
let namespace = Box::new(self.convert_expr(*value));
|
||||
let t = self.convert_ident_type_spec(name, expr.location);
|
||||
|
|
@ -772,7 +775,7 @@ impl ASTConverter {
|
|||
let lhs = self.convert_expr(vals.remove(0));
|
||||
let rhs = self.convert_expr(vals.remove(0));
|
||||
let (kind, cont) = match ops.remove(0) {
|
||||
Comparison::Equal => (TokenKind::Equal, "=="),
|
||||
Comparison::Equal => (TokenKind::DblEq, "=="),
|
||||
Comparison::NotEqual => (TokenKind::NotEq, "!="),
|
||||
Comparison::Less => (TokenKind::Less, "<"),
|
||||
Comparison::LessOrEqual => (TokenKind::LessEq, "<="),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
def f(x: int | None):
|
||||
x + 1 # ERR
|
||||
if x != None:
|
||||
print(x + 1) # OK
|
||||
if isinstance(x, int):
|
||||
print(x + 1) # OK
|
||||
return None
|
||||
|
||||
f(1)
|
||||
|
|
@ -83,3 +83,8 @@ fn exec_typespec() {
|
|||
fn exec_projection() {
|
||||
expect("tests/projection.py", 0, 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exec_narrowing() {
|
||||
expect("tests/narrowing.py", 0, 1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue