aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2021-09-28 15:30:13 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2021-09-28 15:30:13 +0200
commitb99eb75908304d84fbc729ea4209642bb3d82a1c (patch)
tree06551c969a2e5ea0b10c70e431f5c781d04d54d4
parent614d1130c9679e5e943b6be64221515198273cda (diff)
Fix incorrect handling of functions in when clauses using ODIN_OS
-rw-r--r--src/common/ast.odin3
-rw-r--r--tests/signatures_test.odin114
2 files changed, 113 insertions, 4 deletions
diff --git a/src/common/ast.odin b/src/common/ast.odin
index ceda09c..3589848 100644
--- a/src/common/ast.odin
+++ b/src/common/ast.odin
@@ -103,8 +103,7 @@ collect_globals :: proc(file: ast.File, skip_private := false) -> []GlobalExpr {
}
if ident != nil && basic_lit != nil {
-
- if ident.name == "ODIN_OS" && basic_lit.tok.text == ODIN_OS {
+ if ident.name == "ODIN_OS" && basic_lit.tok.text[1:len(basic_lit.tok.text)-1] == ODIN_OS {
if block, ok := when_decl.body.derived.(ast.Block_Stmt); ok {
for stmt in block.stmts {
diff --git a/tests/signatures_test.odin b/tests/signatures_test.odin
index 2716a17..f70c4cc 100644
--- a/tests/signatures_test.odin
+++ b/tests/signatures_test.odin
@@ -372,9 +372,119 @@ ast_index_builtin_len_proc :: proc(t: ^testing.T) {
len(*)
}
`,
- packages = {},
+ packages = {},
};
test.expect_signature_labels(t, &source, {"builtin.len: proc(array: Array_Type) -> (int)"});
+}
+
+@(test)
+ast_signature_on_invalid_package :: proc(t: ^testing.T) {
+
+ source := test.Source {
+ main = `package test
+ import "core:totallyReal"
+ main :: proc() {
+ a := totallyReal.read_cycle_counter(*)
+ }
+ `,
+ packages = {},
+ };
+
+ test.expect_signature_labels(t, &source, {});
+}
+
+@(test)
+ast_signature_variable_pointer :: proc(t: ^testing.T) {
+
+ source := test.Source {
+ main = `package test
+ import "core:totallyReal"
+
+ My_Fun :: proc(a: int) {
+ }
+
+ main :: proc() {
+ my_fun_ptr: My_Fun;
+ my_fun_ptr(*)
+ }
+ `,
+ packages = {},
+ };
+
+ test.expect_signature_labels(t, &source, {"test.My_Fun: proc(a: int)"});
+
+}
+
+@(test)
+ast_signature_global_variable_pointer :: proc(t: ^testing.T) {
+
+ source := test.Source {
+ main = `package test
+ import "core:totallyReal"
+
+ My_Fun :: proc(a: int) {
+ }
+
+ my_fun_ptr: My_Fun;
+
+ main :: proc() {
+ my_fun_ptr(*)
+ }
+ `,
+ packages = {},
+ };
-} \ No newline at end of file
+ test.expect_signature_labels(t, &source, {"test.My_Fun: proc(a: int)"});
+}
+
+@(test)
+index_variable_pointer_signature :: proc(t: ^testing.T) {
+
+ packages := make([dynamic]test.Package);
+
+ append(&packages, test.Package {
+ pkg = "my_package",
+ source = `package my_package
+ My_Fun :: proc(a: int) {
+ }
+
+ my_fun_ptr: My_Fun;
+ `,
+ });
+
+ source := test.Source {
+ main = `package test
+
+ import "my_package"
+ main :: proc() {
+ my_package.my_fun_ptr(*)
+ }
+ `,
+ packages = packages[:],
+ };
+
+ test.expect_signature_labels(t, &source, {"my_package.My_Fun: proc(a: int)"});
+}
+
+/*
+@(test)
+signature_function_inside_when :: proc(t: ^testing.T) {
+
+ source := test.Source {
+ main = `package test
+ when ODIN_OS == "windows" {
+ ProcAllocationFunction :: #type proc"stdcall"(pUserData: rawptr, size: int, alignment: int, allocationScope: SystemAllocationScope) -> rawptr;
+ }
+
+ main :: proc() {
+ ProcAllocationFunction(*)
+ }
+ `,
+ packages = {},
+ };
+
+ test.expect_signature_labels(t, &source, {"test.My_Fun: proc(a: int)"});
+
+}
+*/ \ No newline at end of file