Skip to content

Commit 4751375

Browse files
lucioleKijhogberg
andcommitted
dialyzer: Introduce nominal types
This PR implements [EEP-69: Nominal Types](https://www.erlang.org/eeps/eep-0069) in Dialyzer. As a side effect, nominal types can encode opaque types. We changed all opaque-handling logic and improved opaque warnings in Dialyzer. All existing Erlang type systems are structural: two types are seen as equivalent if their structures are the same. Type comparison are based on the structures of the types, not on how the user explicitly defines them. For example, in the following example, `meter()` and `foot()` are equivalent. The two types can be used interchangeably. Neither of them differ from the basic type integer(). -type meter() :: integer(). -type foot() :: integer(). Nominal typing is an alternative type system, where two types are equivalent if and only if they are declared with the same type name. The EEP proposes one new syntax `-nominal` for declaring nominal types. Under nominal typing, `meter()` and `foot()` are no longer compatible. Whenever a function expects type `meter()`, passing in type `foot()` would result in a Dialyzer error. -nominal meter() :: integer(). -nominal foot() :: integer(). More nominal type-checking rules can be found in the EEP. It is worth noting that most work for adding nominal types and type-checking is in `erl_types.erl`. The rest are changes that removed the previous opaque type-checking, and added an improved version of it using nominal type-checking with reworked warnings. Backwards compatibility for opaque type-checking is **not** preserved by this PR. Previous opaque warnings can appear with slightly different wordings. A new kind of opaque warning `opaque_union` is added, together with a Dialyzer option `no_opaque_union` to turn this kind of warnings off. This PR is likely not bug-free, but not having it in master is blocking other changes to Dialyzer. Once nominal type-checking and the new opaque type-checking are applied to more codebases, we will fix the bugs as they appear. Co-authored-by: John Högberg <[email protected]>
1 parent 9e55c7c commit 4751375

File tree

112 files changed

+3191
-3573
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+3191
-3573
lines changed
48 Bytes
Binary file not shown.
28 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
172 Bytes
Binary file not shown.
1.96 KB
Binary file not shown.
172 Bytes
Binary file not shown.
48 Bytes
Binary file not shown.
408 Bytes
Binary file not shown.
44 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)