compiler: Type Check All Binary Operators

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-05-22 20:42:35 -04:00
parent bc51b4e280
commit 97a672bd6d
4 changed files with 57 additions and 111 deletions
+29
View File
@@ -463,3 +463,32 @@ import TreeSitterP4
)
}
@Test func test_field_read_equality_invalid_type() async throws {
let simple_parser_declaration = """
parser main_parser() {
state start {
transition select (ts.yesno == "testing") {
true: accept;
false: reject;
};
}
};
"""
var test_declarations = VarTypeScopes().enter()
let fields = P4StructFields([
P4StructFieldIdentifier(name: "yesno", withType: P4QualifiedType(P4Boolean())),
P4StructFieldIdentifier(name: "count", withType: P4QualifiedType(P4Int())),
])
let struct_type = P4Struct(withName: Identifier(name: "Testing"), andFields: fields)
test_declarations = test_declarations.declare(identifier: Identifier(name: "ts"), withValue: P4QualifiedType(struct_type))
#expect(
#RequireErrorResult(
Error(
withMessage: "{68, 21}: Could not parse transition select expression selector expression: Types of values used with binary expression are not the same"
),
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
)
}