<commit_before>namespace BooJs.Compiler.Steps

import Boo.Lang.Compiler.Ast
import Boo.Lang.Compiler.Steps
import Boo.Lang.Compiler.TypeSystem(Ambiguous, Internal, EntityType)

class MethodOverloading(AbstractFastVisitorCompilerStep):
"""
Method overloading is performed by suffixing the original method name with a unique
identifier to ensure there are no name collisions in the generated javascript code.

    def foo(s as string):
    def foo(i as int):
    foo(10)
    ---
    def foo$0(s as string):
    def foo$1(i as int):
    foo$1(10)
"""
    def OnMethod(node as Method):
        cls = node.DeclaringType
        if not cls.ContainsAnnotation('method-overload-{0}' % node.Name):
            cls.Annotate('method-overload-{0}' % node.Name)
            type = NameResolutionService.Resolve(cls.Entity, node.Name, EntityType.Method)
            if type isa Boo.Lang.Compiler.TypeSystem.Ambiguous:
                # Create a new method with the original name to raise an error if called
                m = node.CloneNode()
                cls.Members.Insert(cls.Members.IndexOf(node), m)
                m.Parameters.Clear()
                m.Body.Clear()
                m.Body.Add([| raise 'Overloaded method' |])
                Visit m

                entities = (type as Ambiguous).Entities
                for i, entity as Internal.InternalMethod in enumerate(entities):
                    entity.Method.Name += '$' + i

        super(node)

    def OnMethodInvocationExpression(node as MethodInvocationExpression):
        return unless node.Target isa ReferenceExpression
        target = node.Target as ReferenceExpression
        ent = target.Entity as Internal.InternalMethod
        if ent:
            target.Name = ent.Name<commit_msg>Fixed renaming algorithm for method overloads<commit_after>namespace BooJs.Compiler.Steps

import Boo.Lang.Compiler.Ast
import Boo.Lang.Compiler.Steps
import Boo.Lang.Compiler.TypeSystem(Ambiguous, Internal, EntityType)


class MethodOverloading(AbstractFastVisitorCompilerStep):
"""
Method overloading is performed by suffixing the original method name with a unique
identifier to ensure there are no name collisions in the generated javascript code.

    def foo(s as string):
    def foo(i as int):
    foo(10)
    ---
    def foo$0(s as string):
    def foo$1(i as int):
    foo$1(10)
"""
    def OnMethod(node as Method):
        cls = node.DeclaringType
        if not cls.ContainsAnnotation('method-overload-{0}' % node.Name):
            cls.Annotate('method-overload-{0}' % node.Name)
            overloads = [m for m in cls.Members if m.Name == node.Name]
            if len(overloads) > 1:
                # Create a new method with the original name to raise an error if called
                m = node.CloneNode()
                cls.Members.Insert(cls.Members.IndexOf(node), m)
                m.Parameters.Clear()
                m.Body.Clear()
                m.Body.Add([| raise 'Overloaded method' |])
                Visit m

                # Rename overloads to include a unique suffix
                for i, m in enumerate(overloads):
                    m.Name += '$' + i

        super(node)

    def OnMethodInvocationExpression(node as MethodInvocationExpression):
        return unless node.Target isa ReferenceExpression
        target = node.Target as ReferenceExpression
        ent = target.Entity as Internal.InternalMethod
        if ent:
            target.Name = ent.Name
{'fraction_non_alphanumeric': 0.08804849884526558, 'fraction_numerical': 0.005484988452655889, 'mean_word_length': 2.338150289017341, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3217627', 'n_tokens_mistral': 962, 'n_tokens_neox': 922, 'n_words': 283}