Difference between "can call" and "can compile"
Paul Backus
snarwin at gmail.com
Tue Sep 15 11:26:32 UTC 2020
On Tuesday, 8 September 2020 at 20:04:32 UTC, Steven
Schveighoffer wrote:
> Here's what it says when there is no constraint (and when I
> actually call fun inside use):
>
> onlineapp.d(9): Error: undefined identifier oops
> onlineapp.d(4): Error: template instance onlineapp.bad!() error
> instantiating
> onlineapp.d(20): instantiated from here: use!(bad)
>
> This is what I want it to do. Why can't it just do that? Why do
> I need to see 10 more or even 5 more lines of irrelevant error
> messages?
It sounds to me like your problem is that template constraints
are doing the exact thing they're designed to do: causing errors
that would otherwise be reported inside a template to be reported
outside of it.
Re: irrelevant error messages, I think they're unavoidable in the
general case. What if there are multiple template overloads? Only
one of them is going to have the error you care about, but the
compiler has no way to know which one. And likewise with static
if and static assert statements inside the template body.
The optimal solution to this problem, from a
programming-language-theory perspective, is a system like Rust's
traits that allows the compiler to type-check generic code prior
to instantiation. Since we don't have that, we're going to have
to settle for something "good enough."
More information about the Digitalmars-d
mailing list