From ae48ec59c5f15e3f439fe4d351f140786f96479c Mon Sep 17 00:00:00 2001 From: Eric Entin Date: Wed, 3 Aug 2016 11:59:04 -0400 Subject: [PATCH] Do not wait for self in parallel compiler --- lib/elixir/lib/kernel/parallel_compiler.ex | 4 +++- lib/elixir/test/elixir/fixtures/parallel_struct/undef.ex | 5 +++++ lib/elixir/test/elixir/kernel/parallel_compiler_test.exs | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 lib/elixir/test/elixir/fixtures/parallel_struct/undef.ex diff --git a/lib/elixir/lib/kernel/parallel_compiler.ex b/lib/elixir/lib/kernel/parallel_compiler.ex index 34c9bb8fe9e..e6baf5b9f33 100644 --- a/lib/elixir/lib/kernel/parallel_compiler.ex +++ b/lib/elixir/lib/kernel/parallel_compiler.ex @@ -206,8 +206,10 @@ defmodule Kernel.ParallelCompiler do {:waiting, kind, child, ref, on, defining} -> # Oops, we already got it, do not put it on waiting. + # OR + # We're waiting on ourselves, send :found so that we can crash with a better error waiting = - if :lists.any(&match?({^kind, ^on}, &1), result) do + if :lists.any(&match?({^kind, ^on}, &1), result) or on in defining do send child, {ref, :found} waiting else diff --git a/lib/elixir/test/elixir/fixtures/parallel_struct/undef.ex b/lib/elixir/test/elixir/fixtures/parallel_struct/undef.ex new file mode 100644 index 00000000000..8d35959a82b --- /dev/null +++ b/lib/elixir/test/elixir/fixtures/parallel_struct/undef.ex @@ -0,0 +1,5 @@ +defmodule Undef do + def undef do + %__MODULE__{} + end +end diff --git a/lib/elixir/test/elixir/kernel/parallel_compiler_test.exs b/lib/elixir/test/elixir/kernel/parallel_compiler_test.exs index 7c4a009d529..4b475d10448 100644 --- a/lib/elixir/test/elixir/kernel/parallel_compiler_test.exs +++ b/lib/elixir/test/elixir/kernel/parallel_compiler_test.exs @@ -28,6 +28,13 @@ defmodule Kernel.ParallelCompilerTest do end end + test "emits struct undefined error when local struct is undefined" do + fixtures = [fixture_path("parallel_struct/undef.ex")] + assert capture_io(fn -> + assert catch_exit(Kernel.ParallelCompiler.files(fixtures)) == {:shutdown, 1} + end) =~ "Undef.__struct__/1 is undefined, cannot expand struct Undef" + end + test "does not hang on missing dependencies" do fixtures = [fixture_path("parallel_compiler/bat.ex")] assert capture_io(fn ->