Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing backtick in escape.d error message #20677

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

dkorpel
Copy link
Contributor

@dkorpel dkorpel commented Jan 10, 2025

No description provided.

@dkorpel dkorpel added the Review:Trivial typos, formatting, comments label Jan 10, 2025
@dlang-bot
Copy link
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.

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#20677"

@ibuclaw
Copy link
Member

ibuclaw commented Jan 10, 2025

@dkorpel FYI, I expect these tests to fail.

FAIL: gdc.test/fail_compilation/retscope2.d   (internal compiler error: in expand_d_format, at d/d-diagnostic.cc:127)
FAIL: gdc.test/fail_compilation/retscope3.d   (internal compiler error: in expand_d_format, at d/d-diagnostic.cc:127)
FAIL: gdc.test/fail_compilation/retscope6.d   (internal compiler error: in expand_d_format, at d/d-diagnostic.cc:127)
FAIL: gdc.test/fail_compilation/test18282.d   (internal compiler error: in expand_d_format, at d/d-diagnostic.cc:127)

@ibuclaw
Copy link
Member

ibuclaw commented Jan 10, 2025

Doesn't have to be addressed in this PR, one good way to prevent this from recurring is to copy the strict backtick checking from gdc.

Here is where dmd does backtick highlighting.

private void colorSyntaxHighlight(ref OutBuffer buf)
{
//printf("colorSyntaxHighlight('%.*s')\n", cast(int)buf.length, buf[].ptr);
bool inBacktick = false;
size_t iCodeStart = 0;
size_t offset = 0;
for (size_t i = offset; i < buf.length; ++i)
{
char c = buf[i];
switch (c)
{
case '`':
if (inBacktick)
{
inBacktick = false;
OutBuffer codebuf;
codebuf.write(buf[iCodeStart .. i]);
codebuf.writeByte(0);
// escape the contents, but do not perform highlighting except for DDOC_PSYMBOL
colorHighlightCode(codebuf);
buf.remove(iCodeStart, i - iCodeStart);
immutable pre = "";
i = buf.insert(iCodeStart, pre);
i = buf.insert(i, codebuf[]);
break;
}
inBacktick = true;
iCodeStart = i + 1;
break;
default:
break;
}
}
}

At the end of the function there could be an assert to ensure inBacktick is false.

@dkorpel dkorpel force-pushed the safe-error-msg-backtick branch from ff72385 to 3c13e7c Compare January 10, 2025 15:39
@dkorpel
Copy link
Contributor Author

dkorpel commented Jan 10, 2025

At the end of the function there could be an assert to ensure inBacktick is false.

Wouldn't that trigger when an argument contains a single backtick? For example:

int x = "`";
Error: cannot implicitly convert expression `"`"` of type `string` to `int`

@ibuclaw
Copy link
Member

ibuclaw commented Jan 10, 2025

Error: cannot implicitly convert expression ""of typestringtoint`

The format string for that is

cannot implicitly convert expression `%s` of type `%s` to `%s`

So unless highlighting is done after all format specifiers are expanded, then there shouldn't be a problem. Didn't check too closely what dmd is doing.

@dkorpel
Copy link
Contributor Author

dkorpel commented Jan 10, 2025

It's doing syntax highlighting after expanding. Also, some messages are formatted with OutBuffer.printf and passed to error() as a single complete string.

@ibuclaw
Copy link
Member

ibuclaw commented Jan 10, 2025

Alright, so there's something more fundamentally the issue. Will not push the matter for now then. :-)

BTW, gdc rewrites the format string as:

cannot implicitly convert expression %<%s%> of type %<%s%> to %<%s%>

then gcc has it's own printf-style routines that expand it to the right thing.

@dlang-bot dlang-bot merged commit 8b215f8 into dlang:master Jan 10, 2025
41 checks passed
@dkorpel dkorpel deleted the safe-error-msg-backtick branch January 10, 2025 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merge:auto-merge Review:Trivial typos, formatting, comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants