diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2024-09-29 22:21:54 +0200 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2024-09-29 22:21:54 +0200 |
| commit | 632a1ca20e713430bdcfe6bca60ebf269f260c69 (patch) | |
| tree | 7daece8a9f17d17066f6441b219e8ffacbf5afc3 | |
| parent | c68b7f5c26dc0ee8f162b86a2adcc12eb922d71d (diff) | |
Add test and fix generics error.
| -rw-r--r-- | src/server/generics.odin | 5 | ||||
| -rw-r--r-- | tests/completions_test.odin | 48 |
2 files changed, 34 insertions, 19 deletions
diff --git a/src/server/generics.odin b/src/server/generics.odin index ba8c950..23b9773 100644 --- a/src/server/generics.odin +++ b/src/server/generics.odin @@ -427,9 +427,6 @@ resolve_generic_function :: proc { } resolve_generic_function_ast :: proc(ast_context: ^AstContext, proc_lit: ast.Proc_Lit) -> (Symbol, bool) { - - using ast - if proc_lit.type.params == nil { return Symbol{}, false } @@ -505,8 +502,6 @@ resolve_generic_function_symbol :: proc( if poly, ok := name.derived.(^ast.Poly_Type); ok { poly_map[poly.type.name] = clone_expr(call_expr.args[i], ast_context.allocator, nil) } - } else { - return {}, false } } else { return {}, false diff --git a/tests/completions_test.odin b/tests/completions_test.odin index 1f17fcb..cac4285 100644 --- a/tests/completions_test.odin +++ b/tests/completions_test.odin @@ -1,8 +1,8 @@ package tests import "core:fmt" -import "core:testing" import "core:strings" +import "core:testing" import test "src:testing" @@ -1072,16 +1072,12 @@ ast_file_private_completion :: proc(t: ^testing.T) { @(test) ast_file_tag_private_completion :: proc(t: ^testing.T) { - comments := []string{ - "// +private", - "//+private file", - "// +build ignore", - } + comments := []string{"// +private", "//+private file", "// +build ignore"} for comment in comments { - + b := strings.builder_make(context.temp_allocator) - + strings.write_string(&b, comment) strings.write_string(&b, ` package my_package @@ -1096,12 +1092,7 @@ ast_file_tag_private_completion :: proc(t: ^testing.T) { my_package.{*} } `, - packages = { - { - pkg = "my_package", - source = strings.to_string(b), - } - }, + packages = {{pkg = "my_package", source = strings.to_string(b)}}, } test.expect_completion_details(t, &source, ".", {}) @@ -2836,6 +2827,35 @@ ast_generics_function_with_comp_lit_struct :: proc(t: ^testing.T) { } @(test) +ast_generics_struct_poly :: proc(t: ^testing.T) { + source := test.Source { + main = `package main + Pair :: struct($A, $B: typeid) { + a: A, + b: B, + } + + Foo :: struct { + cool: int, + } + + select :: proc($T: typeid, search: []Pair(string, any), allocator := context.temp_allocator) -> []T { + + } + + + main :: proc() { + d := select(Foo, []Pair(string, any){}) + d[0].c{*} + } + `, + } + + test.expect_completion_details(t, &source, ".", {"Foo.cool: int"}) + +} + +@(test) ast_enumerated_array_index_completion :: proc(t: ^testing.T) { source := test.Source { main = `package main |