diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-11-10 21:58:05 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-11-11 13:11:58 -0500 |
| commit | 5b279434986b18d07ceec217c5c402a589ccc0b4 (patch) | |
| tree | eac7bb2993f594bb5471633a92671d9b63833b27 /src/analyze.cpp | |
| parent | de30438ed2efb909538f3177cced441b57eb1a5d (diff) | |
| download | zig-5b279434986b18d07ceec217c5c402a589ccc0b4.tar.gz zig-5b279434986b18d07ceec217c5c402a589ccc0b4.zip | |
implement anon struct literal syntax
This implements stage1 parser support for anonymous struct literal
syntax (see #685), as well as semantic analysis support for anonymous
struct literals and anonymous list literals (see #208). The semantic
analysis works when there is a type coercion in the result location;
inferring the struct type based on the values in the literal is not
implemented yet. Also remaining to do is zig fmt support for this new
syntax and documentation updates.
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 66e1f8984b..ae5b626c29 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -140,7 +140,6 @@ void init_scope(CodeGen *g, Scope *dest, ScopeId id, AstNode *source_node, Scope static ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ZigType *import, Buf *bare_name) { - assert(node == nullptr || node->type == NodeTypeContainerDecl || node->type == NodeTypeFnCallExpr); ScopeDecls *scope = allocate<ScopeDecls>(1); init_scope(g, &scope->base, ScopeIdDecls, node, parent); scope->decl_table.init(4); @@ -346,6 +345,8 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) { switch (status) { case ResolveStatusInvalid: zig_unreachable(); + case ResolveStatusBeingInferred: + zig_unreachable(); case ResolveStatusUnstarted: case ResolveStatusZeroBitsKnown: return true; @@ -362,6 +363,8 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) { switch (status) { case ResolveStatusInvalid: zig_unreachable(); + case ResolveStatusBeingInferred: + zig_unreachable(); case ResolveStatusUnstarted: return true; case ResolveStatusZeroBitsKnown: @@ -6132,6 +6135,8 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { continue; if (instruction->ref_count == 0) continue; + if ((err = type_resolve(g, instruction->value.type, ResolveStatusZeroBitsKnown))) + return ErrorSemanticAnalyzeFail; if (!type_has_bits(instruction->value.type)) continue; if (scope_needs_spill(instruction->scope)) { @@ -6271,6 +6276,8 @@ Error type_resolve(CodeGen *g, ZigType *ty, ResolveStatus status) { switch (status) { case ResolveStatusUnstarted: return ErrorNone; + case ResolveStatusBeingInferred: + zig_unreachable(); case ResolveStatusInvalid: zig_unreachable(); case ResolveStatusZeroBitsKnown: @@ -9038,4 +9045,3 @@ Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str, *out_import = add_source_file(g, target_package, resolved_path, import_code, source_kind); return ErrorNone; } - |
