From 9fccfd8ddc42de2275dad94f357eb3828fd3eeed Mon Sep 17 00:00:00 2001 From: DanielGavin Date: Thu, 11 Jul 2024 19:22:01 +0200 Subject: Add `for in string` support with runes. --- src/server/analysis.odin | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src') diff --git a/src/server/analysis.odin b/src/server/analysis.odin index dd7b3b0..132a054 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -2630,6 +2630,17 @@ make_int_ast :: proc( return ident } +make_rune_ast :: proc( + ast_context: ^AstContext, + pos: tokenizer.Pos, + end: tokenizer.Pos, +) -> ^ast.Ident { + ident := new_type(ast.Ident, pos, end, ast_context.allocator) + ident.name = "rune" + return ident +} + + make_ident_ast :: proc( ast_context: ^AstContext, pos: tokenizer.Pos, @@ -3541,6 +3552,24 @@ get_locals_for_range_stmt :: proc( if symbol, ok := resolve_type_expression(ast_context, stmt.expr); ok { #partial switch v in symbol.value { + case SymbolBasicValue: + if ident, ok := unwrap_ident(stmt.vals[0]); ok { + if v.ident.name == "string" { + store_local( + ast_context, + ident, + make_rune_ast(ast_context, ident.pos, ident.end), + ident.pos.offset, + ident.name, + ast_context.local_id, + ast_context.non_mutable_only, + false, + true, + symbol.pkg, + false, + ) + } + } case SymbolMapValue: if len(stmt.vals) >= 1 { if ident, ok := unwrap_ident(stmt.vals[0]); ok { -- cgit v1.2.3