Commit 4174134108

Andrew Kelley <superjoe30@gmail.com>
2016-02-07 08:23:05
unreachable return type can cast to any other return type
1 parent fc31096
Changed files (2)
src/analyze.cpp
@@ -1655,8 +1655,10 @@ static bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTable
         if (expected_type->data.fn.fn_type_id.is_cold != actual_type->data.fn.fn_type_id.is_cold) {
             return false;
         }
-        if (!types_match_const_cast_only(expected_type->data.fn.fn_type_id.return_type,
-            actual_type->data.fn.fn_type_id.return_type))
+        if (actual_type->data.fn.fn_type_id.return_type->id != TypeTableEntryIdUnreachable &&
+            !types_match_const_cast_only(
+                expected_type->data.fn.fn_type_id.return_type,
+                actual_type->data.fn.fn_type_id.return_type))
         {
             return false;
         }
test/self_hosted.zig
@@ -196,3 +196,15 @@ fn rhs_maybe_unwrap_return() {
     const x = ?true;
     const y = x ?? return;
 }
+
+
+#attribute("test")
+fn implicit_cast_fn_unreachable_return() {
+    wants_fn_with_void(fn_with_unreachable);
+}
+
+fn wants_fn_with_void(f: fn()) { }
+
+fn fn_with_unreachable() -> unreachable {
+    unreachable {}
+}