diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-12-31 18:17:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-31 18:17:24 +0100 |
| commit | e9929c0f41970bcb27dc8dcbc378229ce9742249 (patch) | |
| tree | 7d309632c60b59f7dc8a37a188dcbdc7ed0a21e9 | |
| parent | 6d59cd17b4dc3f0f5b50171642dd6f3b4c756f74 (diff) | |
| parent | 0657d1e2bc4c1de7c3a315b5cdd1bad85566392d (diff) | |
Merge pull request #557 from sheganinans/proc-type-fix
fix proc returning proc with where constraint
| -rw-r--r-- | src/odin/printer/visit.odin | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index 6775230..e135825 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -1648,7 +1648,7 @@ visit_expr :: proc( document = cons(document, text("#force_no_inline")) } - document = cons_with_nopl(document, visit_proc_type(p, v.type^, v.body != nil)) + document = cons_with_nopl(document, visit_proc_type(p, v.type^, v.body != nil, len(v.where_clauses) > 0)) document = cons_with_nopl(document, visit_where_clauses(p, v.where_clauses)) @@ -1663,7 +1663,7 @@ visit_expr :: proc( document = cons_with_nopl(document, text("---")) } case ^Proc_Type: - document = group(visit_proc_type(p, v^, false)) + document = group(visit_proc_type(p, v^, false, false)) case ^Basic_Lit: document = text_token(p, v.tok) case ^Binary_Expr: @@ -2083,7 +2083,12 @@ visit_proc_tags :: proc(p: ^Printer, proc_tags: ast.Proc_Tags) -> ^Document { } @(private) -visit_proc_type :: proc(p: ^Printer, proc_type: ast.Proc_Type, contains_body: bool) -> ^Document { +visit_proc_type :: proc( + p: ^Printer, + proc_type: ast.Proc_Type, + contains_body: bool, + contains_where_clauses: bool, +) -> ^Document { document := text("proc") explicit_calling := false @@ -2136,6 +2141,14 @@ visit_proc_type :: proc(p: ^Printer, proc_type: ast.Proc_Type, contains_body: bo } } + if contains_where_clauses { + if len(proc_type.results.list) == 1 { + if _, ok := proc_type.results.list[0].type.derived.(^ast.Proc_Type); ok { + use_parens = true + } + } + } + if use_parens { document = cons_with_nopl(document, text("(")) document = cons( |