Fix panic parsing seeds when account has qualified path #2268
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a panic caused when Anchor parses seeds that reference an account imported from another file using its full path, eg in code like this:
Here the
post.owner
andpost.id
seeds caused a panic.The cause was:
anchor/lang/syn/src/idl/pda.rs
Line 225 in 8ce18c3
When this runs the struct idents are mapped to non-qualified type names:
["Like", "LoadedLike", "DeletePostEvent", "User", "LoadedUser", "LikeDislikePostEvent", "UpdatePostEvent", "Post", "LoadedPost", "NewPostEvent", "CreateUser", "DeletePost", "LikePost", "CreatePost", "DislikePost", "UpdatePost", "Mutable", "Empty", "ProgramsMap", "WithPrograms", "CpiAccount"]
While the
account
wasdot :: program :: Post
. Since this doesn't match any of the unqualified struct names, it panics on theunwrap
.Here
account
comes from a call to:anchor/lang/syn/src/lib.rs
Lines 199 to 209 in 8ce18c3
This PR updates the call to
ty_name
to remove any import path from the account. Soaccount
is returned asPost
and correctly matches the imported struct name, fixing the panic.