Menu ▾ ▴

#902 Overloaded operators do not respect namespace

open
nobody
None
compiler
2019-05-25
2019-05-25
No

Overloaded operators declared/defined in a namespace, do not respect namespace.

type T
    __ as integer
end type

namespace n1
    operator len( byref arg as T ) as uinteger
        operator = 1
    end operator
end namespace

namespace n2
    operator len( byref arg as T ) as uinteger
        operator = 2
    end operator
end namespace

'' output
'' a.bas(12) error 4: Duplicated definition in 'operator len( byref arg as T ) as uinteger'

1) if operators are continue to be automatically imported to global namespace, then the error should come in the form "Ambiguous call to overloaded function", and code defined within the namespace should prefer the operator defined in that namespace.
2) if operators are not imported automatically to global namespace, then operator resolution should follow same rules as normal procedure lookup using, etc.
3) if allowed, same operator in multiple namespaces, then must be allowed to resolve the operator, as in the example ns1.len(arg) or ns2.len(arg)

The reason for this is that currently and internally, fbc keeps a single global list (chain) for each non-self-op overloaded operator.

Related

Bugs: #903
Feature Requests: #315

Discussion


Log in to post a comment.