Ticket #1133 (closed bug: fixed)

Opened 12 years ago

Last modified 12 years ago

MMD matching does not match 'scalar' with primitive types

Reported by: Austin_Hastings Owned by:
Priority: normal Milestone:
Component: none Version: 1.6.0
Severity: medium Keywords:
Cc: Language:
Patch status: Platform:


When MMD is matching a primitive (int, float, str) argument, it knows about autoboxing and supplies a 1-point manhattan penalty for requiring autoboxing into one of the Scalar types (Integer, Float, etc.)

But MMD does not appear to know about 'scalar' as a superclass of the Scalar types, since it is handing the autoboxing specially. As a result, this code misbehaves:

.sub 'foo' :multi(['scalar'])
	.param pmc x
	say "Scalar!"

.sub 'foo' :multi()
	.param pmc x
	$I0 = isa x, 'scalar'
	print "Scalar? "
	say $I0

.sub 'main' :main
	$P0 = box 1

While foo(1) is not considered a scalar, foo(box(1)) is, which is confusing. (And wrong, IMO.) I suggest recoding the special-case processing for primitive types in manhattan-distance so autobox is considered a "step" in the MRO below 'scalar' for Scalar types.

That is, the MRO for 'Integer' would be {Integer}->scalar->integer. Alternatively, special-casing the 'scalar' PMC type as an extra builtin would work, but smells like a dead fish.

Change History

Changed 12 years ago by whiteknight

  • status changed from new to closed
  • resolution set to fixed

Fixed in r45274. I've added your test case above as proof.

Note: See TracTickets for help on using tickets.