From bccd75317e10cae76364ca37737a0112dfc20a42 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Sat, 6 Jun 2026 16:59:49 +0200 Subject: [PATCH] tests: add subtyping test --- tests/cases/checker/06_subtyping.py | 12 + tests/cases/checker/06_subtyping.py.ref.json | 220 +++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 tests/cases/checker/06_subtyping.py create mode 100644 tests/cases/checker/06_subtyping.py.ref.json diff --git a/tests/cases/checker/06_subtyping.py b/tests/cases/checker/06_subtyping.py new file mode 100644 index 0000000..c334ab8 --- /dev/null +++ b/tests/cases/checker/06_subtyping.py @@ -0,0 +1,12 @@ +v1: int = 3 +v2: float = 4 + + +def maximum(a: float, b: float): + if b > a: + return b + return a + + +v3 = maximum(v1, v2) +v3 = v1 + v2 diff --git a/tests/cases/checker/06_subtyping.py.ref.json b/tests/cases/checker/06_subtyping.py.ref.json new file mode 100644 index 0000000..c3482bc --- /dev/null +++ b/tests/cases/checker/06_subtyping.py.ref.json @@ -0,0 +1,220 @@ +{ + "diagnostics": [ + { + "type": "Error", + "location": { + "start": [ + 12, + 5 + ], + "end": [ + 12, + 12 + ] + }, + "message": "Undefined operation __add__ between BaseType(name='int') and BaseType(name='float')" + }, + { + "type": "Error", + "location": { + "start": [ + 12, + 0 + ], + "end": [ + 12, + 12 + ] + }, + "message": "Cannot assign UnknownType() to v3 of type BaseType(name='float')" + } + ], + "judgments": [ + { + "location": { + "from": "L1:10", + "to": "L1:11" + }, + "expr": { + "_type": "LiteralExpr", + "value": 3 + }, + "type": { + "name": "int" + } + }, + { + "location": { + "from": "L2:12", + "to": "L2:13" + }, + "expr": { + "_type": "LiteralExpr", + "value": 4 + }, + "type": { + "name": "int" + } + }, + { + "location": { + "from": "L6:7", + "to": "L6:8" + }, + "expr": { + "_type": "VariableExpr", + "name": "b" + }, + "type": { + "name": "float" + } + }, + { + "location": { + "from": "L6:11", + "to": "L6:12" + }, + "expr": { + "_type": "VariableExpr", + "name": "a" + }, + "type": { + "name": "float" + } + }, + { + "location": { + "from": "L11:5", + "to": "L11:12" + }, + "expr": { + "_type": "VariableExpr", + "name": "maximum" + }, + "type": { + "name": "maximum", + "pos_args": [], + "args": [ + { + "pos": 0, + "name": "a", + "type": { + "name": "float" + }, + "required": true + }, + { + "pos": 1, + "name": "b", + "type": { + "name": "float" + }, + "required": true + } + ], + "kw_args": [], + "returns": { + "name": "float" + } + } + }, + { + "location": { + "from": "L11:13", + "to": "L11:15" + }, + "expr": { + "_type": "VariableExpr", + "name": "v1" + }, + "type": { + "name": "int" + } + }, + { + "location": { + "from": "L11:17", + "to": "L11:19" + }, + "expr": { + "_type": "VariableExpr", + "name": "v2" + }, + "type": { + "name": "float" + } + }, + { + "location": { + "from": "L11:5", + "to": "L11:20" + }, + "expr": { + "_type": "CallExpr", + "callee": { + "_type": "VariableExpr", + "name": "maximum" + }, + "arguments": [ + { + "_type": "VariableExpr", + "name": "v1" + }, + { + "_type": "VariableExpr", + "name": "v2" + } + ], + "keywords": {} + }, + "type": { + "name": "float" + } + }, + { + "location": { + "from": "L12:5", + "to": "L12:7" + }, + "expr": { + "_type": "VariableExpr", + "name": "v1" + }, + "type": { + "name": "int" + } + }, + { + "location": { + "from": "L12:10", + "to": "L12:12" + }, + "expr": { + "_type": "VariableExpr", + "name": "v2" + }, + "type": { + "name": "float" + } + }, + { + "location": { + "from": "L12:5", + "to": "L12:12" + }, + "expr": { + "_type": "BinaryExpr", + "left": { + "_type": "VariableExpr", + "name": "v1" + }, + "operator": "+", + "right": { + "_type": "VariableExpr", + "name": "v2" + } + }, + "type": {} + } + ] +} \ No newline at end of file