Fixes issue where functions could not be found if local and imported names clashed.

This commit is contained in:
Christoffer Lerno
2022-08-18 20:03:59 +02:00
parent 656faa55bf
commit 1858600449
9 changed files with 66 additions and 8 deletions

View File

@@ -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));

View File

@@ -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)
{

View File

@@ -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)

View File

@@ -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.

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.3.23"
#define COMPILER_VERSION "0.3.24"

View File

@@ -1,6 +1,5 @@
module foo;
import bar;
import bar::abc;
long x = Baz.sizeof;
short y = $evaltype("Baz").sizeof;

View File

@@ -1,6 +1,5 @@
module foo;
import bar;
import bar::abc;
fn void a()
{

View File

@@ -0,0 +1,10 @@
module foo::abc;
import bar;
fn int test1()
{
return abc::test();
}
module bar::abc;
fn int test() { return 1; }

View File

@@ -0,0 +1,10 @@
module foo::abc;
import bar;
fn int test1()
{
return abc::test();
}
module bar::abc;
fn int test() { return 1; }