1
Fork 0

Fix issue resolving overloaded proc when the string passed in came from a different package to the overloaded proc

This commit is contained in:
Brad Lewis 2025-07-10 21:19:42 -04:00
commit 5d627844e1
No known key found for this signature in database
GPG key ID: B8FEDA3F0AC0125A
2 changed files with 72 additions and 1 deletions

View file

@ -399,6 +399,26 @@ are_symbol_untyped_basic_same_typed :: proc(a, b: Symbol) -> (bool, bool) {
return false, false
}
are_symbol_basic_same_keywords :: proc(a, b: Symbol) -> bool {
if a.name != b.name {
return false
}
if _, ok := a.value.(SymbolBasicValue); !ok {
return false
}
if _, ok := b.value.(SymbolBasicValue); !ok {
return false
}
if _, ok := keyword_map[a.name]; !ok {
return false
}
if _, ok := keyword_map[b.name]; !ok {
return false
}
return true
}
is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: Symbol, flags: ast.Field_Flags = {}) -> bool {
// In order to correctly equate the symbols for overloaded functions, we need to check both directions
if same, ok := are_symbol_untyped_basic_same_typed(a, b); ok {
@ -429,7 +449,7 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: Symbol, flags: ast.
#partial switch b_value in b.value {
case SymbolBasicValue:
if .Any_Int in flags {
//Temporary - make a function that finds the base type of basic values
//Temporary - make a function that finds the base type of basic values
//This code only works with non distinct ints
switch a.name {
case "int", "uint", "u32", "i32", "u8", "i8", "u64", "u16", "i16":
@ -438,6 +458,10 @@ is_symbol_same_typed :: proc(ast_context: ^AstContext, a, b: Symbol, flags: ast.
}
}
if are_symbol_basic_same_keywords(a, b) {
return true
}
#partial switch a_value in a.value {
case SymbolBasicValue:
return a.name == b.name && a.pkg == b.pkg

View file

@ -2280,6 +2280,53 @@ ast_hover_struct_field_value_when_not_specifying_type_at_use :: proc(t: ^testing
}
test.expect_hover( t, &source, "test.Foo: .B")
}
@(test)
ast_hover_overload_proc_strings_from_different_packages :: proc(t: ^testing.T) {
packages := make([dynamic]test.Package, context.temp_allocator)
append(
&packages,
test.Package {
pkg = "my_package",
source = `package my_package
foo_int :: proc(a: string, b: int){}
foo_string :: proc(a: string, b: string){}
foo :: proc{
foo_int,
foo_string,
}
`,
},
test.Package {
pkg = "str",
source = `package str
get_str :: proc() -> string {
return "foo"
}
`,
},
)
source := test.Source {
main = `package test
import "my_package"
import "str"
main :: proc() {
foo_str := str.get_str()
my_package.f{*}oo(foo_str, 1)
}
`,
packages = packages[:],
}
test.expect_hover(
t,
&source,
"my_package.foo: proc(a: string, b: int)",
)
}
/*
Waiting for odin fix