diff --git a/src/pystencils/backend/kernelcreation/typification.py b/src/pystencils/backend/kernelcreation/typification.py index 83e6ea93482bef7907a61ccc7f01909fe3cb26b6..9ef649b31ab0d548f8ce67c1aa685b5159b04f0a 100644 --- a/src/pystencils/backend/kernelcreation/typification.py +++ b/src/pystencils/backend/kernelcreation/typification.py @@ -126,8 +126,15 @@ class TypeContext: raise TypificationError( f"Can't typify constant with non-numeric type {self._target_type}" ) - c.apply_dtype(self._target_type) - + if c.dtype is None: + c.apply_dtype(self._target_type) + elif deconstify(c.dtype) != self._target_type: + raise TypificationError( + f"Type mismatch at constant {c}: Constant type did not match the context's target type\n" + f" Constant type: {c.dtype}\n" + f" Target type: {self._target_type}" + ) + case PsSymbolExpr(symb): symb.apply_dtype(self._target_type)