Wiki

Ticket #342 (new defect)

Opened 4 years ago

Last modified 4 years ago

Cannot declare method overloads in mixins

Reported by: nerdzero Owned by:
Priority: major Milestone:
Component: Cobra Compiler Version: 0.9.4
Keywords: mixin Cc:

Description

The following code produces the error message: 'mixin added method "foo" is already in class "Testing"'

mixin Behavior
	def foo(i as int)
		pass

	def foo
		pass

class Testing
	adds Behavior

	pass

Change History

Changed 4 years ago by hopscc

Boxes.cobra about line 1599
This check

if box.declForName(method.name)
    box.throwError('mixin added method "[method.name]" is already in [box.englishName] "[box.name]"')
box.addDecl(method)

Needs to be extended from just checking for an existing name to also check for matching parameters (i.e allow method overloads)

(though now above could be done without needing overload using a default parameter value

mixin Behavior
	def foo(i as int = 0)
		pass


class Testing
	adds Behavior

	def main is shared
		pass

Changed 4 years ago by nerdzero

The optional parameter workaround can't be used if you are trying to implement an interface via the mixin's methods though.

Note: See TracTickets for help on using tickets.