Repository: fika-lang/fika
Pull request #85 (2021-02-14 23:18:31)

Replace Nothing with nil


Patch:
diff --git a/lib/fika/compiler/parser/helper.ex b/lib/fika/compiler/parser/helper.ex
index 0fc5913..08b5ceb 100644
--- a/lib/fika/compiler/parser/helper.ex
+++ b/lib/fika/compiler/parser/helper.ex
@@ -102,7 +102,7 @@ defmodule Fika.Compiler.Parser.Helper do
   end
 
   def do_to_ast({[], line}, :return_type) do
-    {:type, line, :Nothing}
+    {:type, line, nil}
   end
 
   def do_to_ast({[type], _line}, :return_type) do
diff --git a/lib/fika/compiler/parser/types.ex b/lib/fika/compiler/parser/types.ex
index 14a45ec..08c6a7f 100644
--- a/lib/fika/compiler/parser/types.ex
+++ b/lib/fika/compiler/parser/types.ex
@@ -105,11 +105,6 @@ defmodule Fika.Compiler.Parser.Types do
     |> label("float")
     |> reduce({Helper, :to_atom, []})
 
-  nothing_type =
-    string("Nothing")
-    |> label("nothing")
-    |> reduce({Helper, :to_atom, []})
-
   bool_type =
     string("Bool")
     |> label("boolean")
@@ -124,7 +119,6 @@ defmodule Fika.Compiler.Parser.Types do
       string_type,
       int_type,
       float_type,
-      nothing_type,
       atom_type,
       bool_type,
       function_type,
diff --git a/lib/fika/compiler/type_checker.ex b/lib/fika/compiler/type_checker.ex
index 65bad43..72fad52 100644
--- a/lib/fika/compiler/type_checker.ex
+++ b/lib/fika/compiler/type_checker.ex
@@ -60,7 +60,7 @@ defmodule Fika.Compiler.TypeChecker do
 
   def infer_block(env, []) do
     Logger.debug("Block is empty.")
-    {:ok, :Nothing, env}
+    {:ok, nil, env}
   end
 
   def infer_block(env, [exp]) do
diff --git a/lib/fika/compiler/type_checker/types/effect.ex b/lib/fika/compiler/type_checker/types/effect.ex
index 3b6cbd6..b226dd1 100644
--- a/lib/fika/compiler/type_checker/types/effect.ex
+++ b/lib/fika/compiler/type_checker/types/effect.ex
@@ -1,5 +1,5 @@
 defmodule Fika.Compiler.TypeChecker.Types.Effect do
-  defstruct type: :Nothing
+  defstruct type: nil
 
   alias Fika.Compiler.TypeChecker.Types, as: T
 
diff --git a/lib/fika/compiler/type_checker/types/list.ex b/lib/fika/compiler/type_checker/types/list.ex
index 95f5ce4..157a614 100644
--- a/lib/fika/compiler/type_checker/types/list.ex
+++ b/lib/fika/compiler/type_checker/types/list.ex
@@ -1,5 +1,5 @@
 defmodule Fika.Compiler.TypeChecker.Types.List do
-  defstruct type: :Nothing
+  defstruct type: nil
 
   defimpl String.Chars, for: Fika.Compiler.TypeChecker.Types.List do
     def to_string(%{type: type}) do


Test patch:
diff --git a/test/fika/compiler/parser_test.exs b/test/fika/compiler/parser_test.exs
index 364442d..02b3342 100644
--- a/test/fika/compiler/parser_test.exs
+++ b/test/fika/compiler/parser_test.exs
@@ -101,7 +101,7 @@ defmodule Fika.Compiler.ParserTest do
       assert {
                :function,
                [position: {4, 20, 23}],
-               {:foo, [], {:type, {1, 0, 6}, :Nothing},
+               {:foo, [], {:type, {1, 0, 6}, nil},
                 [
                   {:identifier, {2, 10, 13}, :x},
                   {:call, {:-, {3, 14, 19}}, [{:identifier, {3, 14, 19}, :y}], "fika/kernel"}
@@ -121,7 +121,7 @@ defmodule Fika.Compiler.ParserTest do
       assert {
                :function,
                [position: {4, 20, 23}],
-               {:foo, [], {:type, {1, 0, 6}, :Nothing},
+               {:foo, [], {:type, {1, 0, 6}, nil},
                 [
                   {:call, {:-, {3, 16, 19}},
                    [
@@ -254,7 +254,7 @@ defmodule Fika.Compiler.ParserTest do
       """
 
       assert {:function, [position: {3, 18, 21}],
-              {:fnfoo, [], {:type, {1, 0, 8}, :Nothing}, [{:integer, {2, 12, 17}, 123}]}} ==
+              {:fnfoo, [], {:type, {1, 0, 8}, nil}, [{:integer, {2, 12, 17}, 123}]}} ==
                TestParser.function_def!(str)
     end
 
@@ -284,18 +284,18 @@ defmodule Fika.Compiler.ParserTest do
 
     test "with type params" do
       str = """
-      fn foo(a: List(List(List(String)))) : List(Nothing) do
+      fn foo(a: List(List(List(String)))) : List(:nil) do
         x
       end
       """
 
-      assert {:function, [position: {3, 59, 62}],
+      assert {:function, [position: {3, 56, 59}],
               {:foo,
                [
                  {{:identifier, {1, 0, 8}, :a},
                   {:type, {1, 0, 34}, %T.List{type: %T.List{type: %T.List{type: :String}}}}}
-               ], {:type, {1, 0, 51}, %T.List{type: :Nothing}},
-               [{:identifier, {2, 55, 58}, :x}]}} ==
+               ], {:type, {1, 0, 48}, %T.List{type: nil}},
+               [{:identifier, {2, 52, 55}, :x}]}} ==
                TestParser.function_def!(str)
     end
 
@@ -321,7 +321,7 @@ defmodule Fika.Compiler.ParserTest do
 
     test "with union types" do
       code = """
-      fn foo(a: Int | Float, b: Nothing) : :ok | {:error, String} do
+      fn foo(a: Int | Float, b: :nil) : :ok | {:error, String} do
         if true do
           :ok
         else
@@ -338,22 +338,22 @@ defmodule Fika.Compiler.ParserTest do
           %T.Tuple{elements: [:error, :String]}
         ])
 
-      assert {:function, [position: {7, 120, 123}],
+      assert {:function, [position: {7, 117, 120}],
               {:foo,
                [
                  {{:identifier, {1, 0, 8}, :a}, {:type, {1, 0, 21}, %T.Union{types: ^arg_union}}},
-                 {{:identifier, {1, 0, 24}, :b}, {:type, {1, 0, 33}, :Nothing}}
+                 {{:identifier, {1, 0, 24}, :b}, {:type, {1, 0, 30}, nil}}
                ],
-               {:type, {1, 0, 59},
+               {:type, {1, 0, 56},
                 %T.Union{
                   types: ^return_union
                 }},
                [
-                 {{:if, {6, 114, 119}}, {:boolean, {2, 63, 72}, true},
-                  [{:atom, {3, 76, 83}, :ok}],
+                 {{:if, {6, 111, 116}}, {:boolean, {2, 60, 69}, true},
+                  [{:atom, {3, 73, 80}, :ok}],
                   [
-                    {:tuple, {5, 91, 113},
-                     [{:atom, {5, 91, 102}, :error}, {:string, {5, 91, 112}, ["not ok"]}]}
+                    {:tuple, {5, 88, 110},
+                     [{:atom, {5, 88, 99}, :error}, {:string, {5, 88, 109}, ["not ok"]}]}
                   ]}
                ]}} = TestParser.function_def!(code)
     end
@@ -980,7 +980,7 @@ defmodule Fika.Compiler.ParserTest do
       """
 
       assert {:function, [position: {4, 36, 39}],
-              {:foo, [], {:type, {2, 20, 26}, :Nothing}, [{:integer, {3, 30, 35}, 123}]}} ==
+              {:foo, [], {:type, {2, 20, 26}, nil}, [{:integer, {3, 30, 35}, 123}]}} ==
                TestParser.function_def!(str)
     end
 
@@ -992,7 +992,7 @@ defmodule Fika.Compiler.ParserTest do
       """
 
       assert {:function, [position: {3, 40, 43}],
-              {:foo, [], {:type, {1, 0, 6}, :Nothing}, [{:integer, {2, 22, 27}, 123}]}} ==
+              {:foo, [], {:type, {1, 0, 6}, nil}, [{:integer, {2, 22, 27}, 123}]}} ==
                TestParser.function_def!(str)
     end
 
@@ -1014,7 +1014,7 @@ defmodule Fika.Compiler.ParserTest do
       """
 
       assert {:function, [position: {3, 22, 25}],
-              {:foo, [], {:type, {1, 0, 6}, :Nothing}, [{:string, {2, 10, 21}, ["foo#bar"]}]}} ==
+              {:foo, [], {:type, {1, 0, 6}, nil}, [{:string, {2, 10, 21}, ["foo#bar"]}]}} ==
                TestParser.function_def!(str)
     end
 
@@ -1047,7 +1047,7 @@ defmodule Fika.Compiler.ParserTest do
                {
                  :foo,
                  '',
-                 {:type, {1, 0, 6}, :Nothing},
+                 {:type, {1, 0, 6}, nil},
                  [
                    {{:=, {2, 10, 17}}, {:identifier, {2, 10, 13}, :x},
                     {:integer, {2, 10, 17}, 1}},
@@ -1274,8 +1274,8 @@ defmodule Fika.Compiler.ParserTest do
                use_modules: [{"foo/bar", {1, 0, 11}}],
                function_defs: [
                  {:function, [position: {3, 13, 43}],
-                  {:ext1, [], {:type, {3, 13, 21}, :Nothing},
-                   [{:ext_call, {3, 13, 43}, {:Test, :foo, [], :Nothing}}]}},
+                  {:ext1, [], {:type, {3, 13, 21}, nil},
+                   [{:ext_call, {3, 13, 43}, {:Test, :foo, [], nil}}]}},
                  {
                    :function,
                    [position: {4, 44, 107}],
@@ -1295,11 +1295,10 @@ defmodule Fika.Compiler.ParserTest do
                    }
                  },
                  {:function, [position: {8, 131, 134}],
-                  {:foo, [], {:type, {6, 109, 115}, :Nothing},
+                  {:foo, [], {:type, {6, 109, 115}, nil},
                    [{:call, {:baz, {7, 119, 130}}, [], "foo/bar"}]}},
                  {:function, [position: {12, 153, 156}],
-                  {:foo2, [], {:type, {10, 136, 143}, :Nothing},
-                   [{:integer, {11, 147, 152}, 123}]}}
+                  {:foo2, [], {:type, {10, 136, 143}, nil}, [{:integer, {11, 147, 152}, 123}]}}
                ]
              ]
            }
diff --git a/test/fika/compiler/type_checker_test.exs b/test/fika/compiler/type_checker_test.exs
index b172219..170b57a 100644
--- a/test/fika/compiler/type_checker_test.exs
+++ b/test/fika/compiler/type_checker_test.exs
@@ -335,7 +335,7 @@ defmodule Fika.Compiler.TypeCheckerTest do
 
       ast = TestParser.expression!(str)
 
-      assert {:ok, %T.List{type: :Nothing}, _} = TypeChecker.infer_exp(%{}, ast)
+      assert {:ok, %T.List{type: nil}, _} = TypeChecker.infer_exp(%{}, ast)
     end
   end
 
diff --git a/test/integration/operators_test.exs b/test/integration/operators_test.exs
index 2de2913..deb8ec0 100644
--- a/test/integration/operators_test.exs
+++ b/test/integration/operators_test.exs
@@ -170,7 +170,7 @@ defmodule Fika.OperatorsTest do
       assert {
                :function,
                [position: {4, 20, 23}],
-               {:foo, [], {:type, {1, 0, 6}, :Nothing},
+               {:foo, [], {:type, {1, 0, 6}, nil},
                 [
                   {:identifier, {2, 10, 13}, :x},
                   {:call, {:-, {3, 14, 19}}, [{:identifier, {3, 14, 19}, :y}], "fika/kernel"}