Skip to content

fix(engine): handle matches against any struct#343

Merged
doorgan merged 1 commit intoelixir-lang:mainfrom
katafrakt:any-struct-pattern-match
Jan 28, 2026
Merged

fix(engine): handle matches against any struct#343
doorgan merged 1 commit intoelixir-lang:mainfrom
katafrakt:any-struct-pattern-match

Conversation

@katafrakt
Copy link
Contributor

@katafrakt katafrakt commented Jan 28, 2026

Using an "any struct match" (I don't know the proper term, sorry) causes errors being logged during indexing:

14:58:09.984 [debug] Node port message: 
14:58:09.984 [error] Could not expand alias: {:_, [line: 1590, column: 35], nil} at /path/to/file.ex 1590:34

The code causing it is, for example:

  defp normalize_suggestion_data(%_{} = struct) do
    Map.from_struct(struct)
  end

This change adds proper handling to this kind of matches (ignoring them, as they are not useful, but without emitting an error).

@katafrakt katafrakt marked this pull request as ready for review January 28, 2026 14:18
Copy link
Collaborator

@doorgan doorgan left a comment

Choose a reason for hiding this comment

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

Thanks! It works
Let's just assert rather than crashing the test in the ones I commented and it's good to merge

@katafrakt katafrakt force-pushed the any-struct-pattern-match branch from 27ea1b0 to 6085028 Compare January 28, 2026 14:34
@doorgan doorgan merged commit 86fe8ec into elixir-lang:main Jan 28, 2026
37 checks passed
@katafrakt katafrakt deleted the any-struct-pattern-match branch January 28, 2026 14:43
doorgan pushed a commit that referenced this pull request Feb 2, 2026
I noticed that after upgrading to the current newest version
([375391c](375391c))
I still see a lot of the following log
```
Could not expand alias: {:mod, [], MyModule}
```

The should be resolved after #343, but there is a small typo in one of
the heads of `expand_alias(ast_node, reducer)`.
I've hopefully fixed the issue for good by pattern matching against the
AST representation of a variable in the appropriate head clause and
adding tests for the log.

I've specifically avoided against matching patterns like
`%my_macro(){}`, since they may actually contain a reference to a
struct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants