From dfa7d31163ad91c84ca250189f6491729c473f8c Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 23 Oct 2022 02:24:34 -0400 Subject: [PATCH] Methods do not collide and are properly retrievable --- parser/accessors.go | 3 ++- parser/body.go | 14 ++++++++++++-- parser/func_test.go | 6 +++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/parser/accessors.go b/parser/accessors.go index 37bba2b..4c21e0b 100644 --- a/parser/accessors.go +++ b/parser/accessors.go @@ -3,7 +3,8 @@ package parser import "git.tebibyte.media/arf/arf/types" // LookupSection looks returns the section under the give name. If the section -// does not exist, nil is returned. +// does not exist, nil is returned. If a method is being searched for, the type +// name of its receiver should be passed. If not, it should just be left blank. func (tree SyntaxTree) LookupSection (name string) (section Section) { section = tree.sections[name] return diff --git a/parser/body.go b/parser/body.go index eb703b0..f480844 100644 --- a/parser/body.go +++ b/parser/body.go @@ -53,7 +53,17 @@ func (parser *parsingOperation) parseBody () (err error) { // addSection adds a section to the tree, ensuring it has a unique name within // the module. func (tree *SyntaxTree) addSection (section Section) (err error) { - _, exists := tree.sections[section.Name()] + index := section.Name() + + funcSection, isFuncSection := section.(FuncSection) + if isFuncSection { + receiver := funcSection.receiver + if receiver != nil { + index = receiver.what.points.name.trail[0] + "_" + index + } + } + + _, exists := tree.sections[index] if exists { err = section.NewError ( "cannot have multiple sections with the same name", @@ -61,6 +71,6 @@ func (tree *SyntaxTree) addSection (section Section) (err error) { return } - tree.sections[section.Name()] = section + tree.sections[index] = section return } diff --git a/parser/func_test.go b/parser/func_test.go index dabbf4e..8bdea25 100644 --- a/parser/func_test.go +++ b/parser/func_test.go @@ -6,13 +6,13 @@ func TestFunc (test *testing.T) { checkTree ("../tests/parser/func", false, `:arf --- -func ro aBasicExternal +func ro bMethod + @ bird:{Bird} > someInput:Int:mut < someOutput:Int 4 --- external -func ro bMethod - @ bird:{Bird} +func ro aBasicExternal > someInput:Int:mut < someOutput:Int 4 ---