unexpected return values using StrReplace as a BoundFunc object

Post a reply

Confirmation code
Enter the code exactly as it appears. All letters are case insensitive.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: unexpected return values using StrReplace as a BoundFunc object

Re: unexpected return values using StrReplace as a BoundFunc object

Post by A_AhkUser » 22 Apr 2018, 14:34

Hi everyone,

jeeswg wrote:Bump.

Yeah, I'm sorry for the delayed response...

@Helgef your explanation is convincing.

Helgef wrote:Although my imagination cannot come up with any (sensible) real use case when this would be a problem, this topic should probably be moved to bug reports for professional assessment.

Done. I agree with you. In particular, without claiming that everything shoud be retroactive from v2 to v1, it works on v2.

best regards,

Re: unexpected return values using StrReplace as a BoundFunc object

Post by Helgef » 07 Feb 2018, 07:39

I will guess that it is related to the boundfunc being released after the expression is evaluated, since no replacement occurs, the function (regexreplace) probably returns the (address of the) input string, which is also released when the boundfunc is. So the command (msgbox) is passed an invalid pointer. To illustrate,

Code: [Select all]GeSHi © Codebox Plus

MsgBox % Func("RegExReplace").bind("Haystack", "z", "ReplaceText").call() == "Haystack"	; The left hand side of == isn't released before the comparison has been evaluated.
MsgBox % Func("RegExReplace").bind("Haystack", "z", "ReplaceText").call()

If a replacement occurs, or if you assign the result to a variable (within the expression), or if you return the result from a user defined function, the result is copied to a new buffer, which has nothing to do with the boundfunc, hence there is no problem in those cases. /end guessing

Although my imagination cannot come up with any (sensible) real use case when this would be a problem, this topic should probably be moved to bug reports for professional assessment.

Cheers.

v2

Re: unexpected return values using StrReplace as a BoundFunc object

Post by A_AhkUser » 06 Feb 2018, 22:30

Hi jeeswg,

I haven't thought about wrapping the command into a wrapper to see if it concerns only built-in functions, thanks for tightening the problem;)
I searched my txt copy of the documentation, and there weren't any examples of binding the func and calling it, in a one-liner. All of the examples did it in two stages, across two lines.


Cheers, good to know. But I agree with you: users might expect that this would be doable.Btw, I use a lot this kind of one-line syntax and never had such unexpected results.

Since it is question of object syntax and since the use of parentheses and the order of all respective evaluations seems to modulate the behaviour, I first took a look @ objects (general information) in the documentation. However, the only remark I found in this respect concerns the hybrid usage of the dot and the brackets (Objects known limitation).

Re: unexpected return values using StrReplace as a BoundFunc object

Post by jeeswg » 06 Feb 2018, 21:27

- It looks bug-like. I got the same results, although different unexpected characters. By putting in a go-between function, I didn't get any errors. (The correct result is 'Haystack', the string should remain unchanged as it does not contain 'z'.)

Code: [Select all] [Expand]GeSHi © Codebox Plus

- I searched my txt copy of the documentation, and there weren't any examples of binding the func and calling it, in a one-liner. All of the examples did it in two stages, across two lines. However, users might expect that this would be doable.

unexpected return values using StrReplace as a BoundFunc object

Post by A_AhkUser » 06 Feb 2018, 20:52

I fail to understand why all these MsgBoxes don't show the same value respectively. Can someone shed a light on this? It seems to occur only if Needle does not appear in Haystack.

Code: [Select all] [Expand]GeSHi © Codebox Plus



Thank you.

Top