forked from Imagelibrary/binutils-gdb
Refine Ada overload matching
Currently, the overload handling in Ada assumes that any two array types are compatible. However, this is obviously untrue, and a user reported an oddity where comparing two Ada strings resulted in a call to the "=" function for packed boolean arrays. This patch improves the situation somewhat, by requiring that the two arrays have the same arity and compatible base element types. This is still over-broad, but it seems safe and is better than the status quo.
This commit is contained in:
@@ -3930,9 +3930,35 @@ ada_resolve_variable (struct symbol *sym, const struct block *block,
|
||||
return candidates[i];
|
||||
}
|
||||
|
||||
/* Return non-zero if formal type FTYPE matches actual type ATYPE. */
|
||||
/* The term "match" here is rather loose. The match is heuristic and
|
||||
liberal. */
|
||||
static bool ada_type_match (struct type *ftype, struct type *atype);
|
||||
|
||||
/* Helper for ada_type_match that checks that two array types are
|
||||
compatible. As with that function, FTYPE is the formal type and
|
||||
ATYPE is the actual type. */
|
||||
|
||||
static bool
|
||||
ada_type_match_arrays (struct type *ftype, struct type *atype)
|
||||
{
|
||||
if (ftype->code () != TYPE_CODE_ARRAY
|
||||
&& !ada_is_array_descriptor_type (ftype))
|
||||
return false;
|
||||
if (atype->code () != TYPE_CODE_ARRAY
|
||||
&& !ada_is_array_descriptor_type (atype))
|
||||
return false;
|
||||
|
||||
if (ada_array_arity (ftype) != ada_array_arity (atype))
|
||||
return false;
|
||||
|
||||
struct type *f_elt_type = ada_array_element_type (ftype, -1);
|
||||
struct type *a_elt_type = ada_array_element_type (atype, -1);
|
||||
return ada_type_match (f_elt_type, a_elt_type);
|
||||
}
|
||||
|
||||
/* Return non-zero if formal type FTYPE matches actual type ATYPE.
|
||||
The term "match" here is rather loose. The match is heuristic and
|
||||
liberal -- while it tries to reject matches that are obviously
|
||||
incorrect, it may still let through some that do not strictly
|
||||
correspond to Ada rules. */
|
||||
|
||||
static bool
|
||||
ada_type_match (struct type *ftype, struct type *atype)
|
||||
@@ -3970,18 +3996,15 @@ ada_type_match (struct type *ftype, struct type *atype)
|
||||
return false;
|
||||
}
|
||||
|
||||
case TYPE_CODE_ARRAY:
|
||||
return (atype->code () == TYPE_CODE_ARRAY
|
||||
|| ada_is_array_descriptor_type (atype));
|
||||
|
||||
case TYPE_CODE_STRUCT:
|
||||
if (ada_is_array_descriptor_type (ftype))
|
||||
return (atype->code () == TYPE_CODE_ARRAY
|
||||
|| ada_is_array_descriptor_type (atype));
|
||||
else
|
||||
if (!ada_is_array_descriptor_type (ftype))
|
||||
return (atype->code () == TYPE_CODE_STRUCT
|
||||
&& !ada_is_array_descriptor_type (atype));
|
||||
|
||||
[[fallthrough]];
|
||||
case TYPE_CODE_ARRAY:
|
||||
return ada_type_match_arrays (ftype, atype);
|
||||
|
||||
case TYPE_CODE_UNION:
|
||||
case TYPE_CODE_FLT:
|
||||
return (atype->code () == ftype->code ());
|
||||
|
||||
Reference in New Issue
Block a user