Skip to content

Commit f73b48b

Browse files
committed
fixup! Add EEP for native records
1 parent 9f1989b commit f73b48b

1 file changed

Lines changed: 64 additions & 3 deletions

File tree

eeps/eep-0079.md

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ bugs to either runtime or when Dialyzer is run.
345345

346346
#### Validation
347347

348+
NOT_REVIEWED_BY_OTB.
349+
348350
A native record creation is validated at runtime against the
349351
native record definition. Creation fails in the following
350352
cases.
@@ -408,13 +410,15 @@ The following syntax allows accessing field `Field` in any record:
408410
Expr#_.Field
409411
```
410412
411-
This access operation fails with a `{badfield,Field}` error if:
412-
413-
* The field `Field` is not defined in the native-record value.
413+
An access operation fails with a `{badrecord,Expr}` error if:
414414
415415
* The definition of the record was not exported when the native-record
416416
value was created, and it is now used outside its defining module.
417417
418+
This access operation fails with a `{badfield,Field}` error if:
419+
420+
* The field `Field` is not defined in the native-record value.
421+
418422
### Updating native records
419423
420424
The syntax for updating native-record values:
@@ -777,6 +781,63 @@ create non-exported from any module.
777781

778782
The functions in the `records` module are BIFs.
779783

784+
### Compile-time checking of records
785+
786+
NOT_REVIEWED_BY_OTB.
787+
788+
Attempting to create a local record values that lacks a definition is
789+
a compilation error. So is referring to a non-existing field name in
790+
an existing record.
791+
792+
Therefore, both attempts to create records in the following module
793+
are compilation errors:
794+
795+
```erlang
796+
-module(compilation_errors).
797+
-record #empty{}.
798+
799+
create1() ->
800+
#empty{whatever=42}.
801+
802+
create2() ->
803+
#unknown_record{}.
804+
```
805+
806+
Those creation operations are always compilation errors because they
807+
could never succeed at runtime.
808+
809+
All other operations operating on undefined entities result in
810+
compilation warnings. The reason is that they would succeed at runtime
811+
when operating on a record from another version of the same module.
812+
813+
For example, the following operations will all result in a warning:
814+
815+
```erlang
816+
-module(compilation_warnings).
817+
-record #empty{}.
818+
819+
access1(R) ->
820+
R#empty.x.
821+
822+
access2(R) ->
823+
R#unknown_record.x.
824+
825+
update1(R) ->
826+
R#empty{unknown=42}.
827+
828+
update2(R) ->
829+
R#unknown_record{x=0}.
830+
831+
match1(#empty{x=X}) ->
832+
X.
833+
834+
match2(#unknown_record{x=X}) ->
835+
X.
836+
```
837+
838+
The compiler checks neither anonymous operations nor operations on
839+
external records.
840+
780841
### Printing
781842

782843
Here is how printed native-records will look like:

0 commit comments

Comments
 (0)