Skip to content

Commit

Permalink
make invalid record dynamic instead of removing it from stub
Browse files Browse the repository at this point in the history
Summary:
- instead of completely removing a record declaration from stubs if it references a bad type, just make all the fields `dynamic()`
- this fixes eqwalizer crash (from the previous diff) and makes logic more consistent
- this also (effectively) eliminates "unbound_record" type error in eqWAlizer

Reviewed By: michalmuskala, TD5

Differential Revision: D65343028

fbshipit-source-id: 1f79ad1541262ec2ac8f27cd1f2043bd3db45d19
  • Loading branch information
ilya-klyuchnikov authored and facebook-github-bot committed Nov 1, 2024
1 parent cd137e0 commit 82b2224
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ error: reference_to_invalid_type

See https://fb.me/eqwalizer_errors#reference_to_invalid_type

error: unbound_record
┌─ check/src/guards.erl:57:19
57 │ test06_neg() when #invalid{} =/= 2 -> ok.
│ ^^^^^^^^^^ Unbound rec: invalid

See https://fb.me/eqwalizer_errors#unbound_record

error: incompatible_types
┌─ check/src/guards.erl:89:25
Expand All @@ -42,4 +34,4 @@ Context expected type: number()

See https://fb.me/eqwalizer_errors#incompatible_types

5 ERRORS
4 ERRORS
26 changes: 11 additions & 15 deletions crates/elp/src/resources/test/eqwalizer_tests/check/records.pretty
Original file line number Diff line number Diff line change
Expand Up @@ -483,29 +483,25 @@ error: reference_to_invalid_type

See https://fb.me/eqwalizer_errors#reference_to_invalid_type

error: unbound_record
error: incompatible_types
┌─ check/src/records.erl:425:5
425 │ X#invalid.field.
│ ^^^^^^^^^^^^^^^ Unbound rec: invalid
│ ^ X.
Expression has type: term()
Context expected type: #invalid{}

See https://fb.me/eqwalizer_errors#unbound_record
See https://fb.me/eqwalizer_errors#incompatible_types

error: unbound_record
error: incompatible_types
┌─ check/src/records.erl:429:9
429 │ _ = X#invalid.field,
│ ^^^^^^^^^^^^^^^ Unbound rec: invalid

See https://fb.me/eqwalizer_errors#unbound_record
│ ^ X.
Expression has type: term()
Context expected type: #invalid{}

error: unbound_record
┌─ check/src/records.erl:434:5
434 │ X#invalid{field = 2}.
│ ^^^^^^^^^^^^^^^^^^^^ Unbound rec: invalid

See https://fb.me/eqwalizer_errors#unbound_record
See https://fb.me/eqwalizer_errors#incompatible_types

error: reveal_type
┌─ check/src/records.erl:445:27
Expand Down Expand Up @@ -593,4 +589,4 @@ See https://fb.me/eqwalizer_errors#incompatible_types
because
term() is not compatible with atom()

46 ERRORS
45 ERRORS
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,6 @@ error: reference_to_invalid_type

See https://fb.me/eqwalizer_errors#reference_to_invalid_type

error: unbound_record
┌─ check/src/type_aliases.erl:99:9
99 │ convert(#rec1{l = L1}, #rec2{l = L2}) ->
│ ^^^^^^^^^^^^^ Unbound rec: rec1

See https://fb.me/eqwalizer_errors#unbound_record

error: unknown_id
┌─ check/src/type_aliases.erl:104:21
Expand All @@ -206,4 +198,4 @@ error: reference_to_invalid_type

See https://fb.me/eqwalizer_errors#reference_to_invalid_type

23 ERRORS
22 ERRORS
10 changes: 9 additions & 1 deletion crates/eqwalizer/src/ast/trans_valid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,15 @@ impl TransitiveChecker<'_> {
name: t.name.clone(),
references: invalids,
});
stub.records.remove(&t.name);
// we don't know at this point which fields are invalid,
// so replacing all the fields with dynamic type
stub.records.get_mut(&t.name).map(|rec_decl| {
rec_decl.fields.iter_mut().for_each(|field| {
if field.tp.is_some() {
field.tp = Some(Type::DynamicType)
}
})
});
stub.invalid_forms
.push(InvalidForm::InvalidRecDecl(InvalidRecDecl {
location: t.location.clone(),
Expand Down

0 comments on commit 82b2224

Please sign in to comment.