Skip to content

[Debug] Fix regex type names in DebugDescriptionMacro #71379

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

Merged

Conversation

kastiglione
Copy link
Contributor

@kastiglione kastiglione commented Feb 4, 2024

Fixes the way DebugDescriptionMacro produces a regex type name.

The problem was use of backslash escapes that weren't sufficiently escaped. They needed to be double escaped. To avoid this trap, the regexes now use [.] to match a dot, instead of the more conventional \. syntax.

@kastiglione
Copy link
Contributor Author

@swift-ci smoke test

@@ -71,15 +71,19 @@ extension DebugDescriptionMacro: MemberAttributeMacro {
return []
}

// Warning: To use a backslash escape in `typeIdentifier`, it needs to be double escaped. This is because
// the string is serialized to a String literal (an argument to `@_DebugDescriptionProperty`), which
// effectively "consumes" one level of escaping. To avoid mistakes, dots are matched with `[.]` instead
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So a . inside of a character enumeration [] does not match any character?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently.

echo 'Hello. World.' | sed -e 's/[.]/!/g'
Hello! World!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, character classes match their contents literally (generally speaking, there could be some exceptions I am unaware of). This works for other metacharacters too, ex [+], [$], etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of usage is used as an alternative to backslash escaping.

@kastiglione kastiglione merged commit 3a43e7d into main Feb 5, 2024
@kastiglione kastiglione deleted the dl/Debug-Fix-regex-type-names-in-DebugDescriptionMacro branch February 5, 2024 18:49
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.

2 participants