Wiki

Ticket #175 (closed defect: fixed)

Opened 15 years ago

Last modified 15 years ago

Key in Dict gives silently incorrect /unexpected result

Reported by: hopscc Owned by:
Priority: major Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:

Description

Probably from changeset 2143
Now types dont match but silently fails..

class FKID
	def main is shared
		d = {'a':1, 'b':2, 'c':3, 'd':4}
	
		k = 'a'
		if k in d   
			print 'has [k] in dict'
		else
			print 'no [k] in dict'
			
		if d.containsKey(k)  
			print 'has key [k]'
		else
			print 'no key [k]'
			
		k ='x'
		if k in d
			print 'has [k]'
		else
			print 'no [k]'
		if d.containsKey(k)  
			print 'has key [k]'
		else
			print 'no key [k]'

Result:

no a in dict
has key a
no x
no key x

Probably need to trap this case and emit diagnostic
(if continuing down this path (:-))

Change History

Changed 15 years ago by hopscc

  • summary changed from Key in Dict gives silently incorrect result to Key in Dict gives silently incorrect /unexpected result

Changed 15 years ago by Chuck

I was actually working on this in parallel to you filling out this ticket. So with recent checkins, this is now fixed. The error message is:

error: The left expression (k) cannot be "in" the right-hand expression because the left type is "String" and the right-hand expression contains type "KeyValuePair<of String,int>".

Changed 15 years ago by Chuck

  • status changed from new to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.