Skip to content

Fix issue 19718 - check function safety attributes during template deduction - #23707

Open
usefahmed07 wants to merge 4 commits into
dlang:masterfrom
usefahmed07:fix/19718-clean
Open

Fix issue 19718 - check function safety attributes during template deduction#23707
usefahmed07 wants to merge 4 commits into
dlang:masterfrom
usefahmed07:fix/19718-clean

Conversation

@usefahmed07

Copy link
Copy Markdown
Contributor

Fixes #19718

…duction

When deducing a template parameter T from a function-literal argument
against a declared parameter type like `T function(ref S) @safe` or
`T delegate(ref S) @safe`, deduceType's TypeFunction visitor only
checked varargs, linkage, and per-parameter covariance. It never
checked that the argument's own function attributes (in particular
@safe/@System) satisfy what the parameter type requires.

As a result, an @System function literal could be wrongly deduced as
an exact match against an @safe parameter type, and when this
happened for two overloads simultaneously (function pointer vs
delegate), the compiler reported a confusing 'matches multiple
overloads' ambiguity error instead of the real 'no overload is
callable' safety error.

This adds a trust (safety) compatibility check right after the
existing varargs/linkage check, mirroring the same trust-covariance
rule already used elsewhere in the compiler (Type.covariant).

dlang#19718
@dkorpel

dkorpel commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

#23705 broke that test, among other things. It's reverted now #23708

@dkorpel

dkorpel commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

This is a breaking change, and there's more attributes than @safe

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.

Compiler incorrectly lists non-matching overloads as matching in diagnostic

2 participants