Issue Details (XML | Word | Printable)

Key: BOO-1135
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Cedric Vivier
Reporter: Cedric Vivier
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Boo

Wrong op_Implicit behavior

Created: 26/Jan/09 12:42 AM   Updated: 26/Jan/09 01:35 PM   Resolved: 26/Jan/09 01:35 PM
Component/s: Compiler
Affects Version/s: 0.8.2
Fix Version/s: 0.9

Time Tracking:
Not Specified

Testcase included: yes


 Description  « Hide
[extension]
def op_Implicit(s as string):
      return not string.IsNullOrEmpty(s)

x = ""
y = "foo"
print x or y

Above code prints "True" instead of "foo".
In a logical operator bool context the implicit "to bool" must be used only to evaluate operand trueness.

Also if an op_Implicit extension exists on a type, the extension must be chosen in priority over the built-in implicit conversion.

Testcase:

"""
OK
OK
"""

[extension]
def op_Implicit(s as string) as bool:
	return s.Length > 1

[extension] #nullables have a builtin implicit conversion too
def op_Implicit(x as int?) as bool:
	return not x.HasValue

x = "x"
y = "OK"
print x or y #"OK" instead of "x"

a as int? = 10
b as int? = 20
print a or b #20 instead of 10


Cedric Vivier added a comment - 26/Jan/09 01:35 PM

Fixed in rev. 3199