Skip to content

Commit

Permalink
Merge pull request #174 from Glyphack/report-undefined-error
Browse files Browse the repository at this point in the history
  • Loading branch information
Glyphack authored Sep 20, 2023
2 parents 3d33839 + cfdf63d commit dd340fe
Show file tree
Hide file tree
Showing 13 changed files with 601 additions and 238 deletions.
1 change: 1 addition & 0 deletions parser/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ impl Parser {
while !self.eat(Kind::Dedent) && !self.at(Kind::Eof) {
let stmt = self.parse_statement()?;
stmts.extend(stmt);
self.bump(Kind::NewLine);
}
Ok(stmts)
} else {
Expand Down
1 change: 1 addition & 0 deletions typechecker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ruff_python_resolver = { path = "../ruff_python_import_resolver" }
config = "0.13.3"
serde = { version = "1.0.164", features = ["derive"] }
miette = "5.10.0"
thiserror = "1.0.48"

[dev-dependencies]
insta = { version = "1.28.0", features = ["yaml"] }
38 changes: 38 additions & 0 deletions typechecker/src/ast_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,48 @@ pub trait TraversalVisitor {
for case in &m.cases {
for stmt in &case.body {
self.visit_stmt(stmt);
self.visit_match_pattern(&case.pattern);
}
}
}

fn visit_match_pattern(&mut self, _m: &parser::ast::MatchPattern) {
match _m {
MatchPattern::MatchValue(m) => self.visit_expr(&m.value),
MatchPattern::MatchSingleton(m) => self.visit_expr(&m),
MatchPattern::MatchSequence(m) => {
for item in m.iter() {
self.visit_match_pattern(item);
}
},
MatchPattern::MatchStar(m) => self.visit_expr(&m),
MatchPattern::MatchMapping(m) => {
for key in &m.keys {
self.visit_expr(key);
}
for pattern in &m.patterns {
self.visit_match_pattern(pattern);
}
},
MatchPattern::MatchAs(m) => {
if let Some(pattern) = &m.pattern {
self.visit_match_pattern(pattern);
}
},
MatchPattern::MatchClass(m) => {
self.visit_expr(&m.cls);
for pattern in &m.patterns {
self.visit_match_pattern(pattern);
}
},
MatchPattern::MatchOr(m) => {
for pattern in m.iter() {
self.visit_match_pattern(pattern);
}
},
}
}

fn visit_constant(&mut self, _c: &Constant) {
todo!()
}
Expand Down
2 changes: 2 additions & 0 deletions typechecker/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,6 @@ mod tests {
test_type_check_undefined,
"../testdata/inputs/type_check_undefined.py"
);

snap_type!(test_undefined_names, "../testdata/inputs/test_undefined_name.py");
}
76 changes: 76 additions & 0 deletions typechecker/src/type_check/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,79 @@ pub const DICT_TYPE: &str = "builtins.dict";
pub const SET_TYPE: &str = "builtins.set";

pub const ITER_TYPE: &str = "Iterator";

// list of all builtin function names
pub const BUILTINS: &[&str] = &[
"abs",
"aiter",
"all",
"anext",
"any",
"ascii",
"bin",
"bool",
"breakpoint",
"bytearray",
"bytes",
"callable",
"chr",
"classmethod",
"compile",
"complex",
"delattr",
"dict",
"dir",
"divmod",
"enumerate",
"eval",
"exec",
"filter",
"float",
"format",
"frozenset",
"getattr",
"globals",
"hasattr",
"hash",
"help",
"hex",
"id",
"input",
"int",
"isinstance",
"issubclass",
"iter",
"len",
"list",
"locals",
"map",
"max",
"memoryview",
"min",
"next",
"object",
"oct",
"open",
"ord",
"pow",
"print",
"property",
"range",
"repr",
"reversed",
"round",
"set",
"setattr",
"slice",
"sorted",
"staticmethod",
"str",
"sum",
"super",
"tuple",
"type",
"vars",
"zip",
"__import__",
];

Loading

0 comments on commit dd340fe

Please sign in to comment.