Skip to content

Commit b6170b7

Browse files
Add collectTypeRefs for TCore (#630)
*Description of changes:* This PR adds collectTypeRefs for TCore, which fix the bug of unrecognized dependency between Box and Any. Thanks @keyboardDrummer. This PR replaces #618 By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 3cdf200 commit b6170b7

5 files changed

Lines changed: 38 additions & 1 deletion

File tree

Strata/Languages/Laurel/DatatypeGrouping.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def collectTypeRefs : HighTypeMd → List String
3131
collectTypeRefs base ++ args.flatMap collectTypeRefs
3232
| ⟨.Pure base, _⟩ => collectTypeRefs base
3333
| ⟨.Intersection ts, _⟩ => ts.flatMap collectTypeRefs
34+
| ⟨.TCore name, _⟩ => [name]
3435
| _ => []
3536

3637
/-- Get all datatype names that a `DatatypeDefinition` references in its constructor args. -/

Strata/Languages/Python/PythonToLaurel.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ def wrapFieldInAny (ty : HighType) (expr : StmtExprMd) : Except TranslationError
255255
| .TFloat64 => .ok <| mkStmtExprMd (.StaticCall "from_float" [expr])
256256
| .TReal => .ok <| mkStmtExprMd (.StaticCall "from_float" [expr])
257257
| .TString => .ok <| mkStmtExprMd (.StaticCall "from_string" [expr])
258+
| .TCore "Any" => .ok expr
258259
| other => .error (.typeError s!"wrapFieldInAny: no Any constructor for field type '{repr other}'")
259260

260261
/-- Look up a field's HighType, returning `none` if the class or field is not found. -/
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
==== Verification Results ====
3+
List_get_body_calls_List_get_0: ✅ pass
4+
List_take_body_calls_List_take_0: ✅ pass
5+
List_drop_body_calls_List_drop_0: ✅ pass
6+
List_slice_body_calls_List_drop_0: ✅ pass
7+
List_slice_body_calls_List_take_1: ✅ pass
8+
List_set_body_calls_List_set_0: ✅ pass
9+
DictStrAny_get_body_calls_DictStrAny_get_0: ✅ pass
10+
Any_get_body_calls_DictStrAny_get_0: ✅ pass
11+
Any_get_body_calls_List_get_1: ✅ pass
12+
Any_get_body_calls_List_slice_2: ✅ pass
13+
Any_get_body_calls_List_drop_3: ✅ pass
14+
Any_get!_body_calls_DictStrAny_get_0: ✅ pass
15+
Any_get!_body_calls_List_get_1: ✅ pass
16+
Any_set_body_calls_List_set_0: ✅ pass
17+
Any_set!_body_calls_List_set_0: ✅ pass
18+
PFloorDiv_body_calls_Int.SafeDiv_0: ✅ pass
19+
PFloorDiv_body_calls_Int.SafeDiv_1: ✅ pass
20+
PFloorDiv_body_calls_Int.SafeDiv_2: ✅ pass
21+
PFloorDiv_body_calls_Int.SafeDiv_3: ✅ pass
22+
PAnd_body_calls_Any_to_bool_0: ✅ pass
23+
POr_body_calls_Any_to_bool_0: ✅ pass
24+
ret_type: ✅ pass (in prelude file)
25+
ret_type: ✅ pass (in prelude file)
26+
ret_pos: ✅ pass (in prelude file)
27+
assert_name_is_foo: ✅ pass (in prelude file)
28+
assert_opt_name_none_or_str: ✅ pass (in prelude file)
29+
assert_opt_name_none_or_bar: ✅ pass (in prelude file)
30+
ensures_maybe_except_none: ✅ pass (in prelude file)

StrataTest/Languages/Python/run_py_analyze_sarif.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
BOTH_SKIP = {"test_foo_client_folder", "test_invalid_client_type", "test_unsupported_config"}
2323
SKIP_TESTS = BOTH_SKIP | {"test_class_field_use", "test_list", "test_subscription", "test_with_statement", "test_class_field_init", "test_break_continue", "test_try_except", "test_try_except_scoping", "test_loops",
24-
"test_augmented_assign", "test_list_slice"} # sarif pipeline uses PythonToCore which doesn't yet support AugAssign
24+
"test_augmented_assign", "test_list_slice", "test_class_field_any"} # sarif pipeline uses PythonToCore which doesn't yet support AugAssign
2525
SKIP_TESTS_LAUREL = BOTH_SKIP
2626

2727

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class MyClass:
2+
def __init__(self, some_field):
3+
self.some_field: Any = some_field
4+
5+
c = MyClass([1,2])

0 commit comments

Comments
 (0)