diff --git a/lib/std/core/array.c3 b/lib/std/core/array.c3 index 831d6d152..d4bbb402a 100644 --- a/lib/std/core/array.c3 +++ b/lib/std/core/array.c3 @@ -1,10 +1,9 @@ module std::core::array; -import std::core::mem::array; macro tconcat(arr1, arr2) { var $Type = $typeof(arr1[0]); - $Type[] result = mem::array::talloc($Type, arr1.len + arr2.len); + $Type[] result = array::talloc($Type, arr1.len + arr2.len); if (arr1.len > 0) { mem::copy(result.ptr, &arr1[0], arr1.len * $Type.sizeof, $alignof($Type), $alignof($Type)); @@ -19,7 +18,7 @@ macro tconcat(arr1, arr2) macro concat(arr1, arr2) { var $Type = $typeof(arr1[0]); - $Type[] result = mem::array::alloc($Type, arr1.len + arr2.len); + $Type[] result = array::alloc($Type, arr1.len + arr2.len); if (arr1.len > 0) { mem::copy(result.ptr, &arr1[0], arr1.len * $Type.sizeof, $alignof($Type), $alignof($Type)); diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index fed00a9f2..08ac3ddb0 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -1729,6 +1729,7 @@ INLINE Ast *new_ast(AstKind kind, SourceSpan range); INLINE Ast *ast_next(AstId *current_ptr); const char *span_to_string(SourceSpan span); +void span_to_scratch(SourceSpan span); static inline SourceSpan extend_span_with_token(SourceSpan loc, SourceSpan after) { diff --git a/src/compiler/diagnostics.c b/src/compiler/diagnostics.c index a0bdbdbc6..9eac16a3b 100644 --- a/src/compiler/diagnostics.c +++ b/src/compiler/diagnostics.c @@ -209,6 +209,46 @@ void sema_error(ParseContext *context, const char *message, ...) va_end(list); } +// This function is fairly slow, which is a reflection on how +// often it is supposed to be used. +void span_to_scratch(SourceSpan span) +{ + File *file = source_file_by_id(span.file_id); + const char *current = file->contents; + uint32_t row = 1; + uint32_t row_to_find = span.row; + uint32_t length = span.length; + uint32_t col = span.col; + if (!row_to_find || !length || !col) return; + while (row < row_to_find) + { + switch (current++[0]) + { + case '\0': + return; + case '\n': + row++; + default: + break; + } + } + assert(row == row_to_find); + const char *start = current + col - 1; + bool last_was_whitespace = false; + for (uint32_t i = 0; i < length; i++) + { + char c = start[i]; + if (char_is_whitespace(c)) + { + if (!last_was_whitespace) scratch_buffer_append_char(' '); + last_was_whitespace = true; + continue; + } + last_was_whitespace = false; + scratch_buffer_append_char(c); + } +} + // This function is fairly slow, which is a reflection on how // often it is supposed to be used. const char *span_to_string(SourceSpan span) diff --git a/src/compiler/sema_name_resolution.c b/src/compiler/sema_name_resolution.c index 05d267153..8645cdda8 100644 --- a/src/compiler/sema_name_resolution.c +++ b/src/compiler/sema_name_resolution.c @@ -291,8 +291,8 @@ static Decl *sema_resolve_path_symbol(SemaContext *context, NameResolve *name_re // 1. Do we match our own path? if (matches_subpath(unit->module->name, path)) { - // 2. If so just get the symbol. - return module_find_symbol(unit->module, symbol); + // 2. If so try to locally get the symbol. + if ((decl = module_find_symbol(unit->module, symbol))) return decl; } // 3. Loop over imports. diff --git a/src/version.h b/src/version.h index 31fbee015..0a3cf9e8f 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.3.23" \ No newline at end of file +#define COMPILER_VERSION "0.3.24" \ No newline at end of file diff --git a/test/test_suite/compile_time_introspection/sizeof.c3t b/test/test_suite/compile_time_introspection/sizeof.c3t index 531ab71eb..2a5bfb30c 100644 --- a/test/test_suite/compile_time_introspection/sizeof.c3t +++ b/test/test_suite/compile_time_introspection/sizeof.c3t @@ -1,6 +1,5 @@ module foo; import bar; -import bar::abc; long x = Baz.sizeof; short y = $evaltype("Baz").sizeof; diff --git a/test/test_suite/compile_time_introspection/sizeof_errors.c3 b/test/test_suite/compile_time_introspection/sizeof_errors.c3 index 300493acb..e35060e70 100644 --- a/test/test_suite/compile_time_introspection/sizeof_errors.c3 +++ b/test/test_suite/compile_time_introspection/sizeof_errors.c3 @@ -1,6 +1,5 @@ module foo; import bar; -import bar::abc; fn void a() { diff --git a/test/test_suite/import/import_same.c3 b/test/test_suite/import/import_same.c3 new file mode 100644 index 000000000..96bd65b50 --- /dev/null +++ b/test/test_suite/import/import_same.c3 @@ -0,0 +1,10 @@ +module foo::abc; +import bar; + +fn int test1() +{ + return abc::test(); +} + +module bar::abc; +fn int test() { return 1; } \ No newline at end of file diff --git a/test/test_suite2/import/import_same.c3 b/test/test_suite2/import/import_same.c3 new file mode 100644 index 000000000..96bd65b50 --- /dev/null +++ b/test/test_suite2/import/import_same.c3 @@ -0,0 +1,10 @@ +module foo::abc; +import bar; + +fn int test1() +{ + return abc::test(); +} + +module bar::abc; +fn int test() { return 1; } \ No newline at end of file