Does dmd not always compile all of the source code?

Steven Schveighoffer schveiguy at yahoo.com
Wed Dec 6 17:17:21 UTC 2017


On 12/6/17 12:04 PM, A Guy With a Question wrote:

> I really do think, regardless of if this is considered a template 
> expansion, that dmd should be catching these obvious errors. When one 
> writes interfaces and abstract classes they are generally not ready to 
> implement the end class yet. And getting a ton of errors at once when 
> that occurs is really hard to deal with. I really don't understand why 
> the compiler would have issues with this.

So, it is important to note that a template must successfully *parse*, 
but it cannot be semantically analyzed until it is instantiated.

It is no different from C++ templates.

So why wouldn't the compiler fail? Because it has no idea yet what you 
mean by Nullable. It doesn't even know if Nullable will be available or 
not. You could even import Nullable, but Nullable!T may be an error.

This is definitely different from Generics (which I think you are 
familiar with), where there is some semblance of structure implied in 
the wildcard types. With templates, the type can be anything.

It might be possible to do some deduction of whether something will EVER 
compile, but it's probably not worth the extra work.

Did you waste your time? No. It seems like all your errors are simple 
import problems, just fix the bugs, and you should be good!

For the future, the correct way to write templates like this is to 
instantiate them in tests. Use unittesting, and you shouldn't have 
problems like this.

-Steve


More information about the Digitalmars-d-learn mailing list