Refactor Expected Types During Compilation

By adding an expected type to the compilation context, it is
now possible for type checking to occur on keyset expressions
and return statements at the moment that they are being compiled.

Previously, it was necessary to tentatively compile them and then
typecheck afterward.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-04-10 00:59:11 -04:00
parent ad7e5a6f6d
commit b687454389
8 changed files with 112 additions and 115 deletions
+4 -4
View File
@@ -374,12 +374,12 @@ extension FieldAccessExpression: EvaluatableLValueExpression {
}
extension KeysetExpression: EvaluatableExpression {
public func evaluate(execution: Common.ProgramExecution) -> Common.Result<any Common.P4Value> {
return self.kse_evaluate(execution: execution)
public func evaluate(execution: Common.ProgramExecution) -> Result<P4Value> {
return self.key.evaluate(execution: execution)
}
public func type() -> any Common.P4Type {
return self.kse_type()
public func type() -> P4Type {
return self.key.type()
}
}