diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-11-28 14:14:17 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-11-28 14:14:17 -0500 |
| commit | 0b0e0a0a1d41e9574de8dc17c688a4894c5e7f92 (patch) | |
| tree | 0b7cec7ca42e0eca9aa93ab1d1c84f6b018f12a6 | |
| parent | abe36dcee146fd1a13c338d8d65cd303dc223ed4 (diff) | |
Support promoting values to readonly views
| -rw-r--r-- | compile.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -1577,8 +1577,14 @@ CORD compile_to_type(env_t *env, ast_t *ast, type_t *t) return compile_int_to_type(env, ast, t); if (ast->tag == None && Match(ast, None)->type == NULL) return compile_null(t); - CORD code = compile(env, ast); + type_t *actual = get_type(env, ast); + + // Promote values to views-of-values if needed: + if (t->tag == PointerType && Match(t, PointerType)->is_view && actual->tag != PointerType) + return CORD_all("stack(", compile_to_type(env, ast, Match(t, PointerType)->pointed), ")"); + + CORD code = compile(env, ast); if (!promote(env, ast, &code, actual, t)) code_err(ast, "I expected a %T here, but this is a %T", t, actual); return code; |
