Wiki

Ticket #129 (closed defect: fixed)

Opened 9 years ago

Last modified 9 years ago

Cannot use "for a, b ..." with KeyValuePair objects

Reported by: Chuck Owned by: Chuck
Priority: major Milestone: Cobra 0.9
Component: Cobra Compiler Version: 0.8.0
Keywords: for, multi-target-assign, KeyValuePair Cc:

Description

This code produces error messages regarding the for loop (that won't be intelligible to the user):

class X

	shared
	
		def numbered as KeyValuePair<of int, String>*
			yield KeyValuePair<of int, String>(0, 'a')
			yield KeyValuePair<of int, String>(1, 'b')
	
		def main
			for i, s in .numbered
				print i, s

The error is:

x-bug-multiargassign.cobra(11): error: Cannot find an indexer in "forEnumVar5393" whose type is "KeyValuePair<of int,String>".

I'm marking as a bug since this should either work, or provide a nicer message. But what we really want is for this to work.

Also, this is required to use the upcoming IList<of T>.numbered extension method. See ticket:126

Change History

Changed 9 years ago by hopscc

OTOH if numbered returns a 2 element list it will work fine.

you'll get that error message off anything (else) thats not a list (or more
specifically anything not int indexable )

What would be an intelligible error message ??

Changed 9 years ago by hopscc

  • owner changed from hopscc to Chuck
  • status changed from new to assigned

Changed 9 years ago by Chuck

Won't a two element list also be less efficient due to boxing and casting? Using a generic avoids both.

Changed 9 years ago by Chuck

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

Fixed in changeset:1939

Note: See TracTickets for help on using tickets.