Opened 17 months ago

Last modified 17 months ago

#268 new defect

Downcasting against type parameter failed

Reported by: f37yu Owned by:
Priority: major Component: cfa-cc
Version: 1.0 Keywords:

Description (last modified by f37yu)

Minimal reproduction:

forall (T) struct wrap {
    T elem;

forall (T) void foo (wrap(T) x, T y) {

int main() {
    wrap(int) w{10};
    foo (w, 2.0); // error?

Change History (2)

comment:1 Changed 17 months ago by f37yu

Description: modified (diff)

comment:2 Changed 17 months ago by f37yu

To clarify, this particular issue requires a tightly bound parameter T (exact match)
In the call T is forced to be bound to int, so we expect the 2.0 to be (implicitly) downcast to int, but the unify algorithm does not consider downcast as a possibility and only attempts to unify T=int with double (by arithmetic hierarchy) Since T cannot be changed to double it fails.

Actually, the box type is not necessary. We can achieve the tightly bound T by using a pointer instead:

forall (T) void foo (T * x, T y);
int z;
foo (&z, 2.0); // also fails
Note: See TracTickets for help on using tickets.