March 16, 2010 [Issue 3973] New: out contracts fail with ref return types | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=3973 Summary: out contracts fail with ref return types Product: D Version: 2.041 Platform: Other OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: lat7h@virginia.edu --- Comment #0 from Luther Tychonievich <lat7h@virginia.edu> 2010-03-15 20:23:53 PDT --- The following does not compile: ---- ref int buggy(ref int x) out(result){ } body { return ++x; } ---- bug.d(3): Error: result = (x += 1) is not mutable bug.d(3): Error: result = (x += 1) is not an lvalue The first of these statements comes because out contracts are always const (func.c:1111) and thus not mutable. The second comes from statement:3488 where we try to make an assignment expression (created on statement.c:3490) into an lvalue, which assignment expressions are not. Reading through the source, I think what is going on is that ---- out(x) { Y } ... return Z ---- is replaced with ---- const nonref typeof(return) x; // statment.c:3488, func.c:1107..1124 lvalue(x = Z); // statement.c:3490, 3500 goto __returnLabel; // statement.c:3536 __returnLabel: void __ensure(ref typeof(return) x) { Y } // func.c:713..738 __ensure(x); ---- I probably got some of this wrong; I'm not familiar with most of this code. It's not clear to me why we don't instead do ---- typeof(return) __ensure(const typeof(return) x) { Y cast(typeof(return))x; } return __ensure( Z ) ---- which seems at least superficially simpler. I discovered this issue while trying to understand issue 3667, and suspect without evidence that the two might be related. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 18, 2011 [Issue 3973] out contracts fail with ref return types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luther Tychonievich | http://d.puremagic.com/issues/show_bug.cgi?id=3973 Kenji Hara <k.hara.pg@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |k.hara.pg@gmail.com Resolution| |DUPLICATE --- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2011-06-18 07:28:11 PDT --- *** This issue has been marked as a duplicate of issue 3273 *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation