-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Allow using protocol list implementation on improper lists #14366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sabiwara
wants to merge
1
commit into
elixir-lang:main
Choose a base branch
from
sabiwara:improper-list-protocol
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,7 +206,10 @@ defmodule Module.Types.IntegrationTest do | |
assert itself_arg.(Itself.Float) == dynamic(float()) | ||
assert itself_arg.(Itself.Function) == dynamic(fun()) | ||
assert itself_arg.(Itself.Integer) == dynamic(integer()) | ||
assert itself_arg.(Itself.List) == dynamic(list(term())) | ||
|
||
assert itself_arg.(Itself.List) == | ||
dynamic(union(empty_list(), non_empty_list(term(), term()))) | ||
|
||
assert itself_arg.(Itself.Map) == dynamic(open_map(__struct__: if_set(negation(atom())))) | ||
assert itself_arg.(Itself.Port) == dynamic(port()) | ||
assert itself_arg.(Itself.PID) == dynamic(pid()) | ||
|
@@ -483,7 +486,7 @@ defmodule Module.Types.IntegrationTest do | |
dynamic( | ||
%Date{} or %DateTime{} or %NaiveDateTime{} or %Time{} or %URI{} or %Version{} or | ||
%Version.Requirement{} | ||
) or atom() or binary() or float() or integer() or list(term()) | ||
) or atom() or binary() or empty_list() or float() or integer() or non_empty_list(term(), term()) | ||
|
||
where "data" was given the type: | ||
|
||
|
@@ -507,7 +510,7 @@ defmodule Module.Types.IntegrationTest do | |
dynamic( | ||
%Date{} or %DateTime{} or %NaiveDateTime{} or %Time{} or %URI{} or %Version{} or | ||
%Version.Requirement{} | ||
) or atom() or binary() or float() or integer() or list(term()) | ||
) or atom() or binary() or empty_list() or float() or integer() or non_empty_list(term(), term()) | ||
|
||
where "data" was given the type: | ||
|
||
|
@@ -520,6 +523,18 @@ defmodule Module.Types.IntegrationTest do | |
assert_warnings(files, warnings, consolidate_protocols: true) | ||
end | ||
|
||
test "String.Chars protocol dispatch on improper lists" do | ||
files = %{ | ||
"a.ex" => """ | ||
defmodule FooBar do | ||
def example1, do: to_string([?a, ?b | "!"]) | ||
end | ||
""" | ||
} | ||
|
||
assert_no_warnings(files, consolidate_protocols: true) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, if we can add this to one of the existing tests, it would be better, as they can be expensive! |
||
|
||
test "Enumerable protocol dispatch" do | ||
files = %{ | ||
"a.ex" => """ | ||
|
@@ -546,7 +561,7 @@ defmodule Module.Types.IntegrationTest do | |
dynamic( | ||
%Date.Range{} or %File.Stream{} or %GenEvent.Stream{} or %HashDict{} or %HashSet{} or | ||
%IO.Stream{} or %MapSet{} or %Range{} or %Stream{} | ||
) or fun() or list(term()) or non_struct_map() | ||
) or empty_list() or fun() or non_empty_list(term(), term()) or non_struct_map() | ||
|
||
where "date" was given the type: | ||
|
||
|
@@ -575,7 +590,7 @@ defmodule Module.Types.IntegrationTest do | |
but expected a type that implements the Collectable protocol, it must be one of: | ||
|
||
dynamic(%File.Stream{} or %HashDict{} or %HashSet{} or %IO.Stream{} or %MapSet{}) or binary() or | ||
list(term()) or non_struct_map() | ||
empty_list() or non_empty_list(term(), term()) or non_struct_map() | ||
|
||
hint: the :into option in for-comprehensions use the Collectable protocol to build its result. Either pass a valid data type or implement the protocol accordingly | ||
""" | ||
|
@@ -1378,8 +1393,8 @@ defmodule Module.Types.IntegrationTest do | |
end) | ||
end | ||
|
||
defp assert_no_warnings(files) do | ||
assert capture_compile_warnings(files, []) == "" | ||
defp assert_no_warnings(files, opts \\ []) do | ||
assert capture_compile_warnings(files, opts) == "" | ||
end | ||
|
||
defp capture_compile_warnings(files, opts) do | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should format this as
maybe_improper_list(term(), term())
instead (and make a public helper for it in descr)