language: Check For Incorrect Order For Action Parameters
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -18,12 +18,12 @@
|
||||
import Common
|
||||
import Foundation
|
||||
import Macros
|
||||
import P4Lang
|
||||
import Runtime
|
||||
import SwiftTreeSitter
|
||||
import Testing
|
||||
import TreeSitter
|
||||
import TreeSitterP4
|
||||
import P4Lang
|
||||
|
||||
@testable import P4Compiler
|
||||
|
||||
@@ -319,4 +319,81 @@ import P4Lang
|
||||
),
|
||||
Program.Compile(simple_parser_declaration))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func test_simple_control_declaration_with_action_with_params_right_order() async throws {
|
||||
let simple_parser_declaration = """
|
||||
control simple(int x, int y) {
|
||||
action a(inout int ax, bool ay) {
|
||||
ax = 5;
|
||||
}
|
||||
table t {
|
||||
key = {
|
||||
x: exact;
|
||||
y: exact;
|
||||
}
|
||||
}
|
||||
apply {
|
||||
}
|
||||
};
|
||||
"""
|
||||
|
||||
let x = { (tipe: P4QualifiedType) -> Bool in
|
||||
switch tipe.baseType() {
|
||||
case let c as Control: c.name == "simple"
|
||||
default: false
|
||||
}
|
||||
}
|
||||
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
|
||||
#expect(program.InstancesWithTypes(x).count == 1)
|
||||
}
|
||||
|
||||
@Test func test_simple_control_declaration_with_action_with_params_wrong_order() async throws {
|
||||
let simple_parser_declaration = """
|
||||
control simple(int x, int y) {
|
||||
action a(int ax, inout bool ay) {
|
||||
ay = false;
|
||||
}
|
||||
table t {
|
||||
key = {
|
||||
x: exact;
|
||||
y: exact;
|
||||
}
|
||||
}
|
||||
apply {
|
||||
}
|
||||
};
|
||||
"""
|
||||
#expect(
|
||||
#RequireErrorResult(
|
||||
ErrorWithLocation(
|
||||
sourceLocation: SourceLocation(41, 23),
|
||||
withError: "All parameters with direction must precede directionless parameters"),
|
||||
Program.Compile(simple_parser_declaration))
|
||||
)
|
||||
}
|
||||
|
||||
@Test func test_simple_control_declaration_with_action_with_params_wrong_order_interspersed() async throws {
|
||||
let simple_parser_declaration = """
|
||||
control simple(int x, int y) {
|
||||
action a(inout bool aa, int ax, inout bool ay) {
|
||||
aa = false;
|
||||
}
|
||||
table t {
|
||||
key = {
|
||||
x: exact;
|
||||
y: exact;
|
||||
}
|
||||
}
|
||||
apply {
|
||||
}
|
||||
};
|
||||
"""
|
||||
#expect(
|
||||
#RequireErrorResult(
|
||||
ErrorWithLocation(
|
||||
sourceLocation: SourceLocation(41, 38),
|
||||
withError: "All parameters with direction must precede directionless parameters"),
|
||||
Program.Compile(simple_parser_declaration))
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user