www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11857] New: `out` parameter breaks overload resolution

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11857

           Summary: `out` parameter breaks overload resolution
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: ice, rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: verylonglogin.reg gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2014-01-02
17:00:51 MSK ---
This code should compile:
---
void f(int) { }
void f(out int) { }
void t(T)(T) { }
void t(T)(out T) if(false) { } // line 4

void main()
{
    const int n = 1;
    f(n); // line 9
    t(n); // also causes ICE
}
---
main.d(9): Error: constant 1 is not an lvalue
main.d(4): Error: cannot have const out parameter of type const(int)
<access violation>
---

Previously dmd just shown error. Now it also ICE-s with access violation in
template case.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 02 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11857


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2014-01-02 20:37:30 PST ---
https://github.com/D-Programming-Language/dmd/pull/3034

*** This issue has been marked as a duplicate of issue 11822 ***

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 02 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11857



--- Comment #2 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2014-01-03
11:07:39 MSK ---
(In reply to comment #1)
 https://github.com/D-Programming-Language/dmd/pull/3034
 
 *** This issue has been marked as a duplicate of issue 11822 ***

If it really is change issue 11822 title appropriately as this issue has nothing to do with `-de` switch. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 02 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11857



--- Comment #3 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2014-01-12
01:53:22 MSK ---
So do I understand correctly ICE part of the issue is considered a duplicate of
issue 11822 and "This code should compile" part is considered WONTFIX? If so,
where is the documentation claiming such code incorrect?

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 11 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11857



--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2014-01-13 01:09:04 PST ---
(In reply to comment #3)
 So do I understand correctly ICE part of the issue is considered a duplicate of
 issue 11822 and "This code should compile" part is considered WONTFIX? If so,
 where is the documentation claiming such code incorrect?

In short, yes. Even `const int n = 1` is interpreted in compile time, `n` is a local variable that has runtime storage on stack. Therefore, expression `n` makes lvalue, then preferentially matches to `out` parameter. This behavior is intended to reduce confusion at the situation that mixing constant-folding and compile-time/runtime evaluation. Example: void f( immutable int n); void f(ref immutable int n); // accepts only lvalue void foo(int x) { immutable int n = x; // n is evaluated in runtime (when foo is called) f(n); // n matches to ref version } void bar(int x) { immutable int n = 1; // n can be interpreted at compile time, // but still allocated on stack and initialized in runtime. f(n); // n still matches to ref version } D is designed to provide consistent overload resolution result for f(n) in both foo and bar. In other words, variable evaluation and its ref-ness is strictly separated from the CTFE/constant-folding. Conflating them would make hard to understand overload resolution result. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 13 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11857



--- Comment #5 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2014-01-13
18:28:07 MSK ---
(In reply to comment #4)

Thanks, but this doesn't answer the question. Probably I should be more
precise:
1. Why `ref` works and `out` doesn't work (in `ref` case the only matching
non-ref overload is selected)?
2. Why disabled by `if(false)` constraint overload breaks overload resolution?

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 13 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11857



--- Comment #6 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2014-01-13
18:57:38 MSK ---
I segregated Issue 11915 and Issue 11916 for discussion.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 13 2014