www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - UFCS requires explicit this

reply d coder <dlang.coder gmail.com> writes:
--bcaec52c5cfd8b9c7904dbe2860a
Content-Type: text/plain; charset=ISO-8859-1

Greetings

Consider the following code ...

class Foo { // 1
  void foo() { // 2
    bar(); // 3
    this.bar(); // 4
  } // 5
} // 6
void bar(Foo f) { // 7
  import std.stdio; // 8
  writeln("This bar"); // 9
} // 10
void main() { // 11
  Foo test = new Foo; // 12
  test.foo(); // 13
} // 14

DMD is fine with line 4 because of UCFS. But it gives an error for line 3
because it does not get this pointer to bind as argument.

I want to know if it is a DMD bug or whether line 3 would be compilable at
some point in future.

Regards
- Puneet

--bcaec52c5cfd8b9c7904dbe2860a
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Greetings<div><br></div><div>Consider the following code .=
..</div><div><br></div><div><div><div><font face=3D"courier new, monospace"=
class Foo {<span class=3D"" style=3D"white-space:pre">			</span>// 1</font=
</div>

<div><font face=3D"courier new, monospace">=A0 void foo() {<span class=3D""= style=3D"white-space:pre"> </span>// 2</font></div><div><font face=3D"co= urier new, monospace">=A0 =A0 bar();<span class=3D"" style=3D"white-space:p= re"> </span>// 3</font></div> <div><font face=3D"courier new, monospace">=A0 =A0 this.bar();<span class= =3D"" style=3D"white-space:pre"> </span>// 4</font></div><div><font face= =3D"courier new, monospace">=A0 }<span class=3D"" style=3D"white-space:pre"=
				</span>// 5</font></div>

<div><font face=3D"courier new, monospace">}<span class=3D"" style=3D"white= -space:pre"> </span>// 6</font></div><div><font face=3D"courier new, mon= ospace">void bar(Foo f) {<span class=3D"" style=3D"white-space:pre"> </spa= n>// 7</font></div> <div><font face=3D"courier new, monospace">=A0 import std.stdio;<span class= =3D"" style=3D"white-space:pre"> </span>// 8</font></div><div><font face= =3D"courier new, monospace">=A0 writeln(&quot;This bar&quot;);<span class= =3D"" style=3D"white-space:pre"> </span>// 9</font></div> <div><font face=3D"courier new, monospace">}<span class=3D"" style=3D"white= -space:pre"> </span>// 10</font></div><div><font face=3D"courier new, mo= nospace">void main() {<span class=3D"" style=3D"white-space:pre"> </span>= // 11</font></div> <div><font face=3D"courier new, monospace">=A0 Foo test =3D new Foo;<span c= lass=3D"" style=3D"white-space:pre"> </span>// 12</font></div><div><font f= ace=3D"courier new, monospace">=A0 test.foo();<span class=3D"" style=3D"whi= te-space:pre"> </span>// 13</font></div> <div><font face=3D"courier new, monospace">}<span class=3D"" style=3D"white= -space:pre"> </span>// 14</font></div></div></div><div><br></div><div st= yle>DMD is fine with line 4 because of UCFS. But it gives an error for line= 3 because it does not get this pointer to bind as argument.</div> <div style><br></div><div style>I want to know if it is a DMD bug or whethe= r line 3 would be compilable at some point in future.</div><div style><br><= /div><div style>Regards</div><div style>- Puneet</div><div style><br></div> </div> --bcaec52c5cfd8b9c7904dbe2860a--
May 04 2013
next sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
This is to be expected.
May 04 2013
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 05/04/2013 01:57 PM, d coder wrote:
 Timon, you mean such support is planned, or is the current behavior the
 expected behavior.
 ...

The current behaviour is expected. UFCS is a rewrite rule from a.b(args...) to b(a,args...).
May 04 2013
prev sibling parent d coder <dlang.coder gmail.com> writes:
--bcaec52e601d10a70204dbe32f3d
Content-Type: text/plain; charset=ISO-8859-1

Timon, you mean such support is planned, or is the current behavior the
expected behavior.

Regards
- Puneet



On Sat, May 4, 2013 at 4:57 PM, Timon Gehr <timon.gehr gmx.ch> wrote:

 This is to be expected.

--bcaec52e601d10a70204dbe32f3d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Timon, you mean such support is planned, or is the current= behavior the expected behavior.<div><br></div><div>Regards</div><div style=
- Puneet</div><div style><br></div></div><div class=3D"gmail_extra"><br><b=

<div class=3D"gmail_quote">On Sat, May 4, 2013 at 4:57 PM, Timon Gehr <span= dir=3D"ltr">&lt;<a href=3D"mailto:timon.gehr gmx.ch" target=3D"_blank">tim= on.gehr gmx.ch</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" s= tyle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> This is to be expected.<br> </blockquote></div><br></div> --bcaec52e601d10a70204dbe32f3d--
May 04 2013