From 0b0e0a0a1d41e9574de8dc17c688a4894c5e7f92 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 28 Nov 2024 14:14:17 -0500 Subject: Support promoting values to readonly views --- compile.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compile.c b/compile.c index bef60a8a..73a4f02e 100644 --- a/compile.c +++ b/compile.c @@ -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; -- cgit v1.2.3