Skip to content

Commit 9f182f9

Browse files
committed
No longer automatically tag structs as dynamic
1 parent 0c75027 commit 9f182f9

File tree

3 files changed

+24
-35
lines changed

3 files changed

+24
-35
lines changed

lib/elixir/lib/module/types/expr.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ defmodule Module.Types.Expr do
294294
end
295295
end
296296

297-
# TODO: expr.fun(arg)
298297
def of_expr({{:., _, [remote, name]}, meta, args} = expr, stack, context) do
299298
{remote_type, context} = of_expr(remote, stack, context)
300299
{args_types, context} = Enum.map_reduce(args, context, &of_expr(&1, stack, &2))

lib/elixir/lib/module/types/of.ex

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ defmodule Module.Types.Of do
184184
@doc """
185185
Struct handling assuming the args have already been converted.
186186
"""
187-
# TODO: Allow structs fields to be defined. If the fields are defined,
188-
# then the struct is no longer dynamic. And we need to validate args
189-
# against the struct types.
187+
# TODO: Allow structs fields to be defined and validate args against the struct types.
190188
# TODO: Use the struct default values to define the default types.
191189
def struct(struct, args_types, default_handling, meta, stack, context) do
192190
{info, context} = struct_info(struct, meta, stack, context)
@@ -200,7 +198,7 @@ defmodule Module.Types.Of do
200198
:only_defaults -> [{:__struct__, atom([struct])} | defaults]
201199
end
202200

203-
{dynamic(closed_map(pairs)), context}
201+
{closed_map(pairs), context}
204202
end
205203

206204
@doc """

lib/elixir/test/elixir/module/types/expr_test.exs

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -459,31 +459,25 @@ defmodule Module.Types.ExprTest do
459459

460460
test "creating structs" do
461461
assert typecheck!(%Point{}) ==
462-
dynamic(
463-
closed_map(
464-
__struct__: atom([Point]),
465-
x: atom([nil]),
466-
y: atom([nil]),
467-
z: integer()
468-
)
462+
closed_map(
463+
__struct__: atom([Point]),
464+
x: atom([nil]),
465+
y: atom([nil]),
466+
z: integer()
469467
)
470468

471469
assert typecheck!(%Point{x: :zero}) ==
472-
dynamic(
473-
closed_map(
474-
__struct__: atom([Point]),
475-
x: atom([:zero]),
476-
y: atom([nil]),
477-
z: integer()
478-
)
470+
closed_map(
471+
__struct__: atom([Point]),
472+
x: atom([:zero]),
473+
y: atom([nil]),
474+
z: integer()
479475
)
480476
end
481477

482478
test "updating structs" do
483479
assert typecheck!([x], %Point{x | x: :zero}) ==
484-
dynamic(
485-
closed_map(__struct__: atom([Point]), x: atom([:zero]), y: term(), z: term())
486-
)
480+
closed_map(__struct__: atom([Point]), x: atom([:zero]), y: term(), z: term())
487481

488482
assert typeerror!([x = :foo], %Point{x | x: :zero}) ==
489483
~l"""
@@ -493,7 +487,7 @@ defmodule Module.Types.ExprTest do
493487
494488
expected type:
495489
496-
dynamic(%Point{x: term(), y: term(), z: term()})
490+
%Point{x: term(), y: term(), z: term()}
497491
498492
but got type:
499493
@@ -540,7 +534,7 @@ defmodule Module.Types.ExprTest do
540534
541535
the given type does not have the given key:
542536
543-
dynamic(%Point{x: nil, y: nil, z: integer()})
537+
%Point{x: nil, y: nil, z: integer()}
544538
"""
545539
end
546540

@@ -811,17 +805,15 @@ defmodule Module.Types.ExprTest do
811805
812806
where "e" was given the type:
813807
814-
# type: dynamic(
815-
%RuntimeError{__exception__: true, message: term()} or
816-
%SyntaxError{
817-
__exception__: true,
818-
column: term(),
819-
description: term(),
820-
file: term(),
821-
line: term(),
822-
snippet: term()
823-
}
824-
)
808+
# type: %RuntimeError{__exception__: true, message: term()} or
809+
%SyntaxError{
810+
__exception__: true,
811+
column: term(),
812+
description: term(),
813+
file: term(),
814+
line: term(),
815+
snippet: term()
816+
}
825817
# from: types_test.ex:LINE-4
826818
rescue e in [SyntaxError, RuntimeError] ->
827819
"""

0 commit comments

Comments
 (0)