vishnevskiy / ElixirSublime

Elixir plugin for SublimeText 3 providing code completion and linting.
MIT License
364 stars 25 forks source link

Struct undefined, cannot expand struct #35

Open cafrias opened 7 years ago

cafrias commented 7 years ago

Hello there!

I have two modules defined in different files, one is using the struct defined in the other, as the following code explains:

# ./lib/identicon.ex

defmodule Identicon do
  def hash_input(input) do
    hex = :crypto.hash(:md5, input)
      |> :binary.bin_to_list()
    # I'm getting the error in the line below
    %Identicon.Image{hex: hex}
  end
end
# ./lib/image.ex

defmodule Identicon.Image do
  defstruct hex: nil, color: nil, grid: nil, pixel_map: nil
end

The exact error I get from elixirlinter is the following: Error: Identicon.Image.__struct__/0 is undefined, cannot expand struct Identicon.Image

The application is running perfectly when executed using iex -S mix.

It seems that I can't load external dependencies for the current file. My question is how to do that? Is there any better approach?

Thanks in advance!

Yonben commented 7 years ago

+1 here, I'm following the same course and have the same issue.

mRamiroGonzalez commented 7 years ago

+1, same problem. elixirlinter giving this error but the code compiles fine with iex -S mix (elixir 1.4.0 if this can help)

alassiter commented 7 years ago

+1, me too, with elixir 1.5.1

chengwengao commented 7 years ago

+1,me too,CompileError in sublime3 like this: sublime but it work well in terminal: terminal

jenskdsgn commented 6 years ago

+1

TheCraftedGem commented 5 years ago

Anyone figure this out>?

patjhal commented 5 years ago

Wow so yeah got the same thing. Im sorta wondering if its a permissions thing. Im using win10 and sorta wondering if everyone else was using windows. I should mention iex -S mix does not work with mine.

Edited: So I think I worked it out but I am having trouble testing it as elixir seems to be remember things from the terminal. As I looked through the error I felt like it had an issue with the struct being populated or something. I had not done allot of the command line parts of the class and Im assuming neither did the folks on this thread. So I went back and did them and low and behold everything worked. Thing is I could not for the life of me get it to misbehave again. I believe the issue is in the code he had us do "defstruct hex: nil" and then later in the command line he shows how it can be changed and does a "defstruct hex: []" changing it to a list which is then what our program feeds it. When we actually do the "%Identicon.Image{hex: hex}" at the end since hex was a list and it had been defined as a list it was fine but when we had it defined as nil it did not work. Unfortunately as I said once I did it, it worked and I even tried backing up the original project and creating a new one and copying over the lib files to get it to fail but darned if it would not fail. If someone comes across this or is still wrestling with it what I would like you to do is change the "nil" to "[]" in the code and I think then it might work without any command line additions. If someone can do this then please respond back if that is the case. I don't feel like going crazy and reinstalling elixir to get the error back.

TDGithubIntegration commented 5 years ago

Changing "nil" to "[]" did not seem to help with this issue. Same error:
== Compilation error in file lib/identicon.ex == ** (CompileError) lib/identicon.ex:12: Identicon.Image.__struct__/0 is undefined, cannot expand struct Identicon.Image lib/identicon.ex:12: (module)

gus4no commented 4 years ago

Has anyone found a solution to this? I'm following the same course and have the exact same issue