===================================================================
@@ -1246,7 +1246,9 @@ done:
{
c = gfc_constructor_first (head);
for (; c; c = gfc_constructor_next (c))
- gfc_convert_type (c->expr, &ts, 1);
+ if (!gfc_convert_type (c->expr, &ts, 1)
+ && c->expr->ts.type != BT_UNKNOWN)
+ return MATCH_ERROR;
}
}
else
===================================================================
@@ -5030,6 +5030,13 @@ gfc_convert_type_warn (gfc_expr *expr, gfc_typespec *t
if (expr->ts.type == BT_UNKNOWN)
goto bad;
+ /* In building an array constructor, gfortran can end up here when no
+ conversion is required for an intrinsic type. We need to let derive
+ types drop through. */
+ if (from_ts.type != BT_DERIVED
+ && (from_ts.type == ts->type && from_ts.kind == ts->kind))
+ return true;
+
if (expr->ts.type == BT_DERIVED && ts->type == BT_DERIVED
&& gfc_compare_types (&expr->ts, ts))
return true;
===================================================================
@@ -8360,7 +8360,7 @@ gfc_convert_constant (gfc_expr *e, bt type, int kind)
default:
oops:
- gfc_internal_error ("gfc_convert_constant(): Unexpected type");
+ return &gfc_bad_expr;
}
result = NULL;
===================================================================
@@ -0,0 +1,4 @@
+! { dg-do compile }
+program p
+ print *, [integer :: 1, [integer(8) :: 2, ['3']]] ! { dg-error "Can't convert" }
+end
===================================================================
@@ -0,0 +1,7 @@
+! { dg-do run }
+program p
+ real :: a(2) = [real :: 1, [integer :: (real(k), k=2,1), 2]]
+ real :: b(1) = [real :: [integer :: (dble(k), k=1,0), 2]]
+ if (a(1) /= 1. .or. a(2) /= 2. .or. b(1) /= 2.) stop 1
+end
+
===================================================================
@@ -0,0 +1,4 @@
+! { dg-do compile }
+program foo
+ print *, [integer :: 1, [integer(8) :: 2, '3']] ! { dg-error "Can\'t convert" }
+end program foo