Solving a constraint hiding an error in a function literal

Salih Dincer salihdb at hotmail.com
Sat Feb 4 04:11:04 UTC 2023


On Friday, 3 February 2023 at 20:20:48 UTC, Steven Schveighoffer 
wrote:
> 
> The problem with this is that your constraint then has to 
> become:
>
> ```d
> foo(alias bar) if (__traits(compiles, 
> exprUsingBar).hasOnlyImplementationIssues)
> ```
> That `hasOnlyImplementationIssues` is going to be messy, 
> difficult to implement, and basically redoing all that the 
> compiler is already doing. Plus, if it's just a string, it 
> might have to change with compiler versions. Essentially, 
> changing error messages becomes a breaking change.

I'm trying to understand their, but neither I will understand 
their nor they will understand me!  However, they can see that I 
am struggling with the following non-simple example for sink 
their differences:

```d
// line 2:
auto foo(E)(E value = E.min)
{
    auto a = E.min; /*
    auto a = E.max; //*/
// line 7:
    assert(a == value);
    return 0;
}

auto bar(alias func)(int b = 0)
if (__traits( compiles, func(1) ))
{
   assert(func(b - 1));
   return 0;
}

void main()
{
   enum Eco { False, True }

   Eco eco;
   assert(eco == Eco.min);
//foo(1);    //core.exception.AssertError @source_file.d(7): 
Assertion failure
#line 1
   foo!Eco; // okay

//foo(++eco);//core.exception.AssertError @source_file.d(7): 
Assertion failure
#line 2
   //bar!foo; //core.exception.AssertError @source_file.d(7): 
Assertion failure

   alias fn = function int (int a) {
     import std.stdio;
     "funy a = ".writeln(a);
     return 0;
   };

   bar!fn(42); /* okay: "funy a = 41
                * core.exception.AssertError
                * @source_file.d(14): Assertion failure
                */

}
```
I love and appreciate you all. There is no my question, but I 
don't understand what is being mentioned in this discussion. 
Because I see that doing constraint with __traits is useless...

I can not see! 😀

SDB at 79


More information about the Digitalmars-d mailing list