Registers a new definition of a user variable. This function will return an error if the value supplied does not match the type the variable was declared to have.
(&mut self, var: Variable, val: Value)
| 487 | /// an error if the value supplied does not match the type the variable was |
| 488 | /// declared to have. |
| 489 | pub fn try_def_var(&mut self, var: Variable, val: Value) -> Result<(), DefVariableError> { |
| 490 | log::trace!("try_def_var: {var:?} = {val:?}"); |
| 491 | |
| 492 | let var_ty = *self |
| 493 | .func_ctx |
| 494 | .variables |
| 495 | .get(var) |
| 496 | .ok_or(DefVariableError::DefinedBeforeDeclared(var))?; |
| 497 | if var_ty != self.func.dfg.value_type(val) { |
| 498 | return Err(DefVariableError::TypeMismatch(var, val)); |
| 499 | } |
| 500 | |
| 501 | self.func_ctx.ssa.def_var(var, val, self.position.unwrap()); |
| 502 | Ok(()) |
| 503 | } |
| 504 | |
| 505 | /// Register a new definition of a user variable. The type of the value must be |
| 506 | /// the same as the type registered for the variable. |