diff --git a/releasenotes.md b/releasenotes.md index a0fa88b1d..3bac86fc2 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -28,6 +28,7 @@ - Change `int!` to `int?` syntax. - New `fault` declarations. - Enum associated values can reference the calling enum. +- Improve error message on `foo ?? io::EOF` with missing '?' #2036 ### Fixes - Fix address sanitizer to work on MachO targets (e.g. MacOS). diff --git a/src/compiler/linker.c b/src/compiler/linker.c index f7c79c662..fdf5f5e62 100644 --- a/src/compiler/linker.c +++ b/src/compiler/linker.c @@ -452,7 +452,7 @@ static void linker_setup_android(const char ***args_ref, Linker linker_type, boo #elif _WIN32 #define ANDROID_HOST_TAG "windows-x86_64" #else - #error Unknown Host OS + error_exit("Unsupported OS for Android host"); #endif if (is_no_pie(compiler.platform.reloc_model)) add_plain_arg("-no-pie"); diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 759be06de..8ead09c9e 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -7803,6 +7803,10 @@ static inline bool sema_expr_analyse_or_error(SemaContext *context, Expr *expr, Type *common = type_find_max_type(type, else_type); if (!common) { + if (else_type == type_anyfault) + { + RETURN_SEMA_ERROR(right, "There is no common type for %s and %s, did you perhaps forget a '?' after the last expression?", type_quoted_error_string(type), type_quoted_error_string(else_type)); + } RETURN_SEMA_ERROR(right, "Cannot find a common type for %s and %s.", type_quoted_error_string(type), type_quoted_error_string(else_type)); } if (!cast_implicit(context, left, common, false)) return false; diff --git a/test/test_suite/errors/or_and_rethrow_missing_question.c3 b/test/test_suite/errors/or_and_rethrow_missing_question.c3 new file mode 100644 index 000000000..d0f8ce373 --- /dev/null +++ b/test/test_suite/errors/or_and_rethrow_missing_question.c3 @@ -0,0 +1,25 @@ +module faults; +fault + EXAMPLE, + DOG_ATE_MY_HOMEWORK, + MY_TEXTBOOK_CAUGHT_FIRE, + DISTRACTED_BY_CAT_PICTURES; + + +module testing_v0_7; +import faults; +import std::io; + +fn int main(String[] args) +{ + + int? foo = faults::EXAMPLE?; + + if (catch foo) + { + // This is issue 2036 + foo = foo ?? faults::DISTRACTED_BY_CAT_PICTURES; // #error: did you perhaps forget a '?' + } + + return 0; +} \ No newline at end of file