Skip to content

Commit fbc618e

Browse files
authored
Refactor the current type checker for return type inference (#13928)
The main goal is to allow checking to continue even if it finds typing violations, so we can infer return types. The violations are replaced by dynamic(). Only the first violation is reported to avoid cascading warnings.
1 parent e8a6709 commit fbc618e

File tree

8 files changed

+488
-595
lines changed

8 files changed

+488
-595
lines changed

lib/elixir/lib/module/behaviour.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ defmodule Module.Behaviour do
3333
module: module,
3434
file: file,
3535
line: line,
36-
# Map containing the callbacks to be implemented
3736
callbacks: %{},
38-
# list of warnings {message, env}
3937
warnings: []
4038
}
4139
end

lib/elixir/lib/module/types.ex

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,9 @@ defmodule Module.Types do
5252
end
5353

5454
defp warnings_from_clause(meta, args, guards, body, stack, context) do
55-
with {:ok, _types, context} <- Pattern.of_head(args, guards, meta, stack, context),
56-
{:ok, _type, context} <- Expr.of_expr(body, stack, context) do
57-
context.warnings
58-
else
59-
{:error, context} -> context.warnings
60-
end
55+
{_types, context} = Pattern.of_head(args, guards, meta, stack, context)
56+
{_type, context} = Expr.of_expr(body, stack, context)
57+
context.warnings
6158
end
6259

6360
@doc false
@@ -83,10 +80,12 @@ defmodule Module.Types do
8380
%{
8481
# A list of all warnings found so far
8582
warnings: [],
86-
# Information about all vars and their types
83+
# All vars and their types
8784
vars: %{},
88-
# Information about variables and arguments from patterns
89-
pattern_info: nil
85+
# Variables and arguments from patterns
86+
pattern_info: nil,
87+
# If type checking has found an error/failure
88+
failed: false
9089
}
9190
end
9291
end

0 commit comments

Comments
 (0)