digitalmars.D - opDispatch & with
- John Chapman (15/15) Feb 17 2023 If I call opDispatch with a name that is also a type inside a
- drug007 (3/22) Feb 17 2023 you are trying to assign a value `Suit.diamonds` to a type `Suit`. Could...
- drug007 (18/19) Feb 17 2023 [snipped]
- drug007 (4/6) Feb 17 2023 [snipped]
- John Chapman (5/7) Feb 17 2023 I'm trying to assign Suit.diamonds to a property of Card named
- drug007 (2/10) Feb 18 2023 My bad, sorry for noise
- Paul Backus (4/7) Feb 17 2023 I think this is the same bug reported here:
- John Chapman (2/4) Feb 17 2023 Thanks for appending this to the bug report.
If I call opDispatch with a name that is also a type inside a ```with``` statement, I get an error. ```d enum Suit { clubs, spades, hearts, diamonds } struct Card { void opDispatch(string s)(.Suit) {} } void main() { Card c; with (c) Suit = .Suit.diamonds; // Error: `Suit` is not an lvalue and cannot be modified } ``` Is this a bug? It compiles without error if I call opDispatch!"Suit" directly.
Feb 17 2023
17.02.2023 22:30, John Chapman пишет:If I call opDispatch with a name that is also a type inside a ```with``` statement, I get an error. ```d enum Suit { clubs, spades, hearts, diamonds } struct Card { void opDispatch(string s)(.Suit) {} } void main() { Card c; with (c) Suit = .Suit.diamonds; // Error: `Suit` is not an lvalue and cannot be modified } ``` Is this a bug? It compiles without error if I call opDispatch!"Suit" directly.you are trying to assign a value `Suit.diamonds` to a type `Suit`. Could you describe what you want to do?
Feb 17 2023
17.02.2023 23:55, drug007 пишет:17.02.2023 22:30, John Chapman пишет:[snipped] Probably you meant something like this: ```D import std; enum Suit { clubs, spades, hearts, diamonds } struct Card { void opDispatch(string s)(Suit t) { pragma(msg, s); // compile time output - suit writeln(t); // runtime output - diamonds } } void main() { Card c; with (c) suit = .Suit.diamonds; } ```
Feb 17 2023
18.02.2023 00:06, drug007 пишет:17.02.2023 23:55, drug007 пишет:[snipped] I think in you initial example the compiler does not call `opDispatch` at all because it recognizes `Suit` as a type.17.02.2023 22:30, John Chapman пишет:
Feb 17 2023
On Friday, 17 February 2023 at 20:55:03 UTC, drug007 wrote:you are trying to assign a value `Suit.diamonds` to a type `Suit`. Could you describe what you want to do?I'm trying to assign Suit.diamonds to a property of Card named "Suit". I know properties are usually lower case, and that calling "c.Suit = Suit.diamonds" works. Just wonder why the compiler seems to overlook opDispatch here.
Feb 17 2023
18.02.2023 00:44, John Chapman пишет:On Friday, 17 February 2023 at 20:55:03 UTC, drug007 wrote:My bad, sorry for noiseyou are trying to assign a value `Suit.diamonds` to a type `Suit`. Could you describe what you want to do?I'm trying to assign Suit.diamonds to a property of Card named "Suit". I know properties are usually lower case, and that calling "c.Suit = Suit.diamonds" works. Just wonder why the compiler seems to overlook opDispatch here.
Feb 18 2023
On Friday, 17 February 2023 at 19:30:02 UTC, John Chapman wrote:If I call opDispatch with a name that is also a type inside a[...]Is this a bug? It compiles without error if I call opDispatch!"Suit" directly.I think this is the same bug reported here: https://issues.dlang.org/show_bug.cgi?id=18866
Feb 17 2023
On Friday, 17 February 2023 at 20:56:57 UTC, Paul Backus wrote:I think this is the same bug reported here: https://issues.dlang.org/show_bug.cgi?id=18866Thanks for appending this to the bug report.
Feb 17 2023