On this page
B2001: expression has the wrong type
Catalog status: active. Default severity: error. Stable name: type-mismatch. Family: Types and constraints.
The expression's type is not the one this place requires. Ada does not convert between types implicitly (except that literals and named numbers adapt to any integer or real type).
Example (Vada)
Flag : Boolean := 1;
if Count then ... -- Count is an Integer, a condition must be BooleanExample (Varc)
var flag: Boolean = 1;
if count { ... } // count is an Integer, a condition must be Boolean
What to do (Vada)
Use a value of the expected type: Flag : Boolean := True;, if Count > 0 then. Between numeric types, convert explicitly: Long_Integer (Count).
What to do (Varc)
Use a value of the expected type: var flag: Boolean = True;, if count > 0 {. Between numeric types, convert explicitly: Long_Integer(count).
Regression source and further reading
Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.
See types and constraints, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.