2017-03-05 8 views
1

どこから来たのかわからない構文エラーがあります。with..do..else文に奇妙な構文エラーがあります

# find or create the user. 
    # if you login with oauth2, your account will auto created 
    def find_or_create(%Auth{provider: :github} = auth) do 
    with 
     {:notfound} <- check_github_email(auth.info.email), 
     {:notfound} <- check_google_email(auth.info.email) 
    do 
     create(auth) 
    else 
     {:ok, persona} -> update(auth, persona) 
    end 
    end 

これは、次のエラーを返します:

== Compilation error on file web/models/persona_from_auth.ex == 
** (SyntaxError) web/models/persona_from_auth.ex:18: syntax error before: do 
    (elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1 

ライン18は、作成()の呼び出しの前の行です。ここ(persona_from_auth.exで)私の関数です。

正しいエリキシルのバージョンを確認しました。 mix.exsで私は1.2を持っていましたが、1.4.2に変更しましたが、それと同じエラーです。コンパイルでまだ1.2が使用されている可能性はありますか?それをどのようにチェックするのですか?

答えて

2

with後の最初の文では、同じ行になければなりませんいずれか、または引数がかっこ内にする必要があり、さもなければエリクシールあなたはwith/0を呼び出すようにして、以下の行が、その結果、意味がありませんしようとしていると考えて構文エラー。

次のいずれかの作業をする必要があります:

with {:notfound} <- check_github_email(auth.info.email), 
    {:notfound} <- check_google_email(auth.info.email)) 
do 
with(
    {:notfound} <- check_github_email(auth.info.email), 
    {:notfound} <- check_google_email(auth.info.email) 
) do 
+0

をありがとうございました。 'with'と' do'と 'else'の間にはいくつかの主要な違いがありますか?後者はそれ自身で行なわれます。 – raarts

+1

はい、 'do'とelseは言語キーワードですが、' with'はそうではありません。 'do'や' else'という名前の関数や変数を作成することはできません。 'iex'で' do = 1'、 'else = 1'、' with = 1'を試すことができます。 'with'だけが動作します。 – Dogbert

関連する問題