Boo

Wrong op_Implicit behavior

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 0.8.2
  • Fix Version/s: 0.9
  • Component/s: Compiler
  • Labels:
    None
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

[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

Activity

Hide
Cedric Vivier added a comment -

Fixed in rev. 3199

Show
Cedric Vivier added a comment - Fixed in rev. 3199

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: