Skip to content

False negatives for A = B expressions #77

@albsch

Description

@albsch

Describe the bug

ELP has trouble finding type spec violations when using A = B expressions.

To Reproduce

Here are three equivalent code snippets in a module example.erl, only the error in t3 is detected.

-module(example).
-compile([export_all, nowarn_export_all]).

-spec t1() -> ok.
t1() ->
  [] = foo.

-spec t2() -> ok.
t2() ->
  case foo of
    A = [] -> A
  end.

-spec t3() -> ok.
t3() ->
  case foo of
    [] -> []
  end.

Expected behavior

Similar to t3, a type error in t2 and t1 should be detected.

Actual behavior

Only a type error in t3 is detected.

> ./elp eqwalize-all                                                                                 
Loading build info                                                                                      
Loading applications      ████████████████████                                                          
Seeding database                                                                                        
Compiling dependencies                                                                                  
Gathering modules         ████████████████████ 3/3                                                      
Parsing modules                                                                                         
EqWAlizing                                                                                            
error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types)
   ┌─ src/example.erl:19:11
   │
19 │     [] -> []
   │           ^^ [].
Expression has type:   []
Context expected type: 'ok'

1 ERROR

Context

ELP release with eqwalizer support enabled, and VS code plugin.

./elp version
elp 1.1.0+build-2025-11-04

Example project attached.

example.zip

Is there a reason why type information is lost for the bound variable A in t2 or why [] is not used as the return type for the expression [] = foo in t1?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions