On this page
B2012: conversion between unrelated types
Catalog status: active. Default severity: error. Stable name: invalid-conversion. Family: Types and constraints.
A type conversion T (X) is allowed between numeric types, between types derived from one another, and between array types with the same component type and number of dimensions (Ada RM 4.6). Other conversions, such as an integer to Boolean or between unrelated enumerations, are not.
Example (Vada)
B : Boolean := Boolean (1);Example (Varc)
let b: Boolean = Boolean(1);
What to do (Vada)
Compute the value instead (B : Boolean := N /= 0;), or use T'Val and T'Pos for enumeration positions.
What to do (Varc)
Compute the value instead (let b: Boolean = n != 0;), or use T::Val and T::Pos for enumeration positions.
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.