-
Notifications
You must be signed in to change notification settings - Fork 153
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
Inspect fails to find views due to guardType(value:namespacedPrefixes:inspectionCall:)
incorrectly failing
#268
Comments
static guardType(value:namespacedPrefixes:inspectionCall:)
guardType(value:namespacedPrefixes:inspectionCall:)
incorrecting failing
guardType(value:namespacedPrefixes:inspectionCall:)
incorrecting failingguardType(value:namespacedPrefixes:inspectionCall:)
incorrectly failing
Hey @cameroncooke I'm trying to replicate the issue you're facing, tried various ways of defining views in extensions, including in a local .framework bundle - the view is unwrapped with no issues. |
Usually reflection shows the namespaces of custom types as |
You can also prepare a PR. I would advise adding tests that verify |
String extension
hasPrefix(regex:wholeMatch:)
doesn't handle reserved RegEx symbols and causes false negatives when checking type prefixes.This is especially true when the type's description includes context information like module name, as an example:
Currently, in my project, I get the error:
This in fact of course is false, the two type strings match, the issue is the injecting of the string and treating it as
regex
.The Regex expression
(extension in MyModule):MyModule.MyComponent
does not have any matches for the literal String(extension in MyModule):MyModule.MyComponent
.The reason for this is:
(
and)
are special characters used to denote the beginning and the end of a capture group..
between the namespace and symbol name is technically also invalid but works because it will match any single character including a literal.
.Reproduction
In my case, the issue was caused because my view type was created within an extension in order to namespace it, i.e:
Regex
Also while investigating this issue the code below seems a little questionable:
Again injecting regex into
String.hasPrefix(_:)
in theremoving(prefix:)
method via theremovingSwiftUINamespace()
method and counting the literal "prefix" characters to return a substring.I did consider opening a pull request and working on a fix but I don't have enough knowledge around why some of this works the way it does to feel confident about changing it.
I did however create three unit tests to exercise the issues:
BaseTypesTests.swift:
The last two tests fail, also the last test is an assumption of what the code is there for.
The text was updated successfully, but these errors were encountered: