Skip to content

Fix #20994 - Initialization of a struct-typed template parameter from…#22921

Open
dkorpel wants to merge 1 commit intodlang:masterfrom
dkorpel:template-param-construction
Open

Fix #20994 - Initialization of a struct-typed template parameter from…#22921
dkorpel wants to merge 1 commit intodlang:masterfrom
dkorpel:template-param-construction

Conversation

@dkorpel
Copy link
Copy Markdown
Contributor

@dkorpel dkorpel commented Apr 13, 2026

… a different type fails

… from a different type fails

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dlang-bot
Copy link
Copy Markdown
Contributor

Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

  • In preparation for migrating from Bugzilla to GitHub Issues, the issue reference syntax has changed. Please add the word "Bugzilla" to issue references. For example, Fix Bugzilla Issue 12345 or Fix Bugzilla 12345.(Reminder: the edit needs to be done in the Git commit message, not the GitHub pull request.)

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#22921"

@thewilsonator
Copy link
Copy Markdown
Contributor

Bunch of build kite failures

@dkorpel
Copy link
Copy Markdown
Contributor Author

dkorpel commented Apr 13, 2026

All from unit-threaded

../.dub/packages/unit-threaded/2.2.3/unit-threaded/subpackages/property/source/unit_threaded/randomized/gen.d(125,23): Error: cannot implicitly convert expression `0` of type `int` to `int[]`
struct Gen(T, T low = 0, T high = 6.022E23) if(from!"std.traits".isFloatingPoint!T) {
                      ^
../.dub/packages/unit-threaded/2.2.3/unit-threaded/subpackages/property/source/unit_threaded/randomized/gen.d(406,1):        while evaluating: `static assert(isGen!(Gen!(int[], 1LU, 1024LU)))`
static assert(isGen!(Gen!(int[])));
^

@dkorpel
Copy link
Copy Markdown
Contributor Author

dkorpel commented Apr 13, 2026

I think I need to gag the errors raised by initializer semantic during speculative template instantiation

@dkorpel
Copy link
Copy Markdown
Contributor Author

dkorpel commented Apr 19, 2026

This is weird, looks like also before this PR, default values are evaluated and error checked even if the template constraint fails:

int gen(T)(T a) if (true) => 1;
int gen(T, T min = ERR)(T a) if (false) => 2;
enum x = gen(3);

Results in:

Error: undefined identifier `ERR`

While I would expect the second overload to only be speculatively instantiated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Initialization of a struct-typed template parameter from a different type fails.

3 participants