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
Return to search
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 made changes - 26/Jan/09 01:13 AM
Field Original Value New Value
Summary op_Implicit must be used only to evaluate operand trueness in a logical operator expression op_Implicit in bool context must be used only to evaluate operand trueness
Cedric Vivier made changes - 26/Jan/09 02:45 AM
Description {code}
[extension]
def op_Implicit(s as string):
      return not string.IsNullOrEmpty(s)

x = ""
y = "foo"
print x or y
{code}

Above code prints "True" instead of "foo".
{code}
[extension]
def op_Implicit(s as string):
      return not string.IsNullOrEmpty(s)

x = ""
y = "foo"
print x or y
{code}

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:
{code}
"""
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

z as int? = 5
if not z:
print "OK"
{code}
Summary op_Implicit in bool context must be used only to evaluate operand trueness Wrong op_Implicit behavior
Cedric Vivier made changes - 26/Jan/09 03:22 AM
Description {code}
[extension]
def op_Implicit(s as string):
      return not string.IsNullOrEmpty(s)

x = ""
y = "foo"
print x or y
{code}

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:
{code}
"""
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

z as int? = 5
if not z:
print "OK"
{code}
{code}
[extension]
def op_Implicit(s as string):
      return not string.IsNullOrEmpty(s)

x = ""
y = "foo"
print x or y
{code}

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:
{code}
"""
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
{code}
Cedric Vivier added a comment - 26/Jan/09 01:35 PM

Fixed in rev. 3199


Cedric Vivier made changes - 26/Jan/09 01:35 PM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]