From 528c151a55a76451b278057c40b29242241a70fd Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 27 May 2019 17:39:56 +0200 Subject: Reject undefined as type Make analyze_type_expr behave like ir_resolve_type when the user tries to use `undefined` as a type. Closes #2436 --- src/analyze.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/analyze.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index 4f58fd07f6..a1b1c56670 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -981,6 +981,17 @@ ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) { return g->builtin_types.entry_invalid; assert(result->special != ConstValSpecialRuntime); + // Reject undefined as valid `type` type even though the specification + // allows it to be casted to anything. + // See also ir_resolve_type() + if (result->special == ConstValSpecialUndef) { + add_node_error(g, node, + buf_sprintf("expected type 'type', found '%s'", + buf_ptr(&g->builtin_types.entry_undef->name))); + return g->builtin_types.entry_invalid; + } + + assert(result->data.x_type != nullptr); return result->data.x_type; } -- cgit v1.2.3