Skip to content

Conversation

lexmag
Copy link
Member

@lexmag lexmag commented Dec 13, 2015

Closes #4070.

unless is_atom(key) do
raise ArgumentError,
"the Access for keywords expect the key to be an atom, got: " <> inspect(key)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be cleaner to move this to its own clause.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made it at first place but decided to keep list-related logic grouped, but have no strong feelings one way or the other. 😄

@lexmag lexmag force-pushed the access-error branch 5 times, most recently from bec1a7b to 2f68c0a Compare December 14, 2015 22:13
@lexmag lexmag changed the title Make Access syntax fail to compile for unsupported literals Make Access syntax fail to compile for unsupported values Dec 14, 2015
rewrite(?access, _DotMeta, 'get', Meta, [Arg, _], Env)
when ?is_literal(Arg) orelse element(1, Arg) == '{}' orelse element(1, Arg) == '<<>>' ->
elixir_errors:compile_error(Meta, ?m(Env, file),
"the Access is not available for the value: ~ts", ['Elixir.Macro':to_string(Arg)]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"the Access syntax"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this place handles not only Access syntax [] but also actual Access calls.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be alright

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or if you want, be explicit: "the Access syntax and calls to Access.get/2 are not available for..."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be strange to say "Access syntax" for Access.get(1, :foo) call.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"the Access syntax and calls to Access.get/2 are not available for the value: 1"

@josevalim
Copy link
Member

I've added just tiny comments, :shipit:

lexmag added a commit that referenced this pull request Dec 15, 2015
Make Access syntax fail to compile for unsupported values
@lexmag lexmag merged commit a4ffd55 into elixir-lang:master Dec 15, 2015
@lexmag lexmag deleted the access-error branch December 15, 2015 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants