gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
17.93k stars 748 forks source link

Record with function param in guard causes compile error #3614

Closed Neilerino closed 1 month ago

Neilerino commented 1 month ago

Bumped into this case in a project I was working on last night. If I try to use a record which includes a function as a parameter I get an erlang compilation error. Running with latest release of gleam. Here's my basic repro steps:

// test_gleam.gleam
import gleam/io
import other_file

pub fn main() {
  let case_var = ["test", "test2"]
  case case_var {
    [head, ..] if head == other_file.case_test.input_string -> {
      io.println("test")
    }
    _ -> {
      io.println("not test")
    }
  }
}
// other_file.gleam
pub type Test {
  Test(input_string: String, func: fn(Int) -> Int)
}

pub fn add_one(x: Int) -> Int {
  x + 1
}

pub const case_test = Test("test", add_one)

gleam run output snippet with trace logging enabled:

DEBUG download_deps: locking_build_directory path="/Users/Neilerino/Programming/test_gleam/build/packages"
TRACE download_deps: reading_file path="/Users/Neilerino/Programming/test_gleam/gleam.toml"
DEBUG download_deps: reading_manifest_toml
TRACE download_deps: reading_file path="/Users/Neilerino/Programming/test_gleam/manifest.toml"
DEBUG download_deps: manifest_up_to_date
TRACE download_deps: reading_file path="/Users/Neilerino/Programming/test_gleam/build/packages/packages.toml"
DEBUG download_deps: locking_build_directory path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang"
DEBUG download_deps: locking_build_directory path="/Users/Neilerino/Programming/test_gleam/build/dev/javascript"
DEBUG download_deps: locking_build_directory path="/Users/Neilerino/Programming/test_gleam/build/prod/erlang"
DEBUG download_deps: locking_build_directory path="/Users/Neilerino/Programming/test_gleam/build/prod/javascript"
DEBUG download_deps: locking_build_directory path="/Users/Neilerino/Programming/test_gleam/build/lsp/erlang"
DEBUG download_deps: locking_build_directory path="/Users/Neilerino/Programming/test_gleam/build/lsp/javascript"
TRACE download_deps: writing_file path="/Users/Neilerino/Programming/test_gleam/build/packages/packages.toml"
TRACE reading_file path="/Users/Neilerino/Programming/test_gleam/gleam.toml"
TRACE reading_file path="/Users/Neilerino/Programming/test_gleam/gleam.toml"
TRACE reading_file path="/Users/Neilerino/Programming/test_gleam/gleam.toml"
 INFO Compiling packages
DEBUG locking_build_directory path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang"
TRACE reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_version"
TRACE reading_file path="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/gleam.toml"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@list.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@io.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@int.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@queue.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bytes_builder.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@regex.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string_builder.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@function.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bool.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@uri.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@float.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@set.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@iterator.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@option.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@pair.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@result.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dict.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@order.cache_meta"
TRACE compile{package=gleam_stdlib}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache_meta"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/order
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@order.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/float
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@float.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/int
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@int.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/option
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@option.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/dict
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dict.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/pair
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@pair.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/list
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@list.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/result
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@result.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/iterator
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@iterator.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/string_builder
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string_builder.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/string
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/bit_array
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/bool
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bool.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/bytes_builder
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bytes_builder.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/dynamic
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/function
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@function.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/io
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@io.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/queue
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@queue.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/regex
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@regex.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/set
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@set.cache"
DEBUG compile{package=gleam_stdlib}: module_to_load_from_cache module=gleam/uri
TRACE compile{package=gleam_stdlib}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@uri.cache"
 INFO compile{package=gleam_stdlib}: analysing_modules count=0
DEBUG compile{package=gleam_stdlib}: performing_code_generation
DEBUG compile{package=gleam_stdlib}: copying_native_source_files
TRACE compile{package=gleam_stdlib}: reading_directory path="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@list.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@float.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@queue.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/dict.mjs"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@iterator.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@io.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@dynamic.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@string_builder.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@bool.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@bit_array.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@option.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@result.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@pair.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@order.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@regex.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@function.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@int.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@uri.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@bytes_builder.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@set.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@string.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam@dict.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam_stdlib.erl"
DEBUG compile{package=gleam_stdlib}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleam_stdlib/src/gleam_stdlib.mjs"
TRACE compile{package=gleam_stdlib}: writing_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleam_stdlib/ebin/gleam_stdlib.app"
DEBUG compile{package=gleam_stdlib}: skipping_entrypoint_generation
DEBUG compile{package=gleam_stdlib}: no_erlang_to_compile
TRACE reading_file path="/Users/Neilerino/Programming/test_gleam/build/packages/gleeunit/gleam.toml"
TRACE compile{package=gleeunit}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleeunit/_gleam_artefacts/gleeunit@should.cache_meta"
TRACE compile{package=gleeunit}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleeunit/_gleam_artefacts/gleeunit.cache_meta"
DEBUG compile{package=gleeunit}: module_to_load_from_cache module=gleeunit
TRACE compile{package=gleeunit}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleeunit/_gleam_artefacts/gleeunit.cache"
DEBUG compile{package=gleeunit}: module_to_load_from_cache module=gleeunit/should
TRACE compile{package=gleeunit}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleeunit/_gleam_artefacts/gleeunit@should.cache"
 INFO compile{package=gleeunit}: analysing_modules count=0
DEBUG compile{package=gleeunit}: performing_code_generation
DEBUG compile{package=gleeunit}: copying_native_source_files
TRACE compile{package=gleeunit}: reading_directory path="/Users/Neilerino/Programming/test_gleam/build/packages/gleeunit/src"
DEBUG compile{package=gleeunit}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleeunit/src/gleeunit_ffi.mjs"
DEBUG compile{package=gleeunit}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleeunit/src/gleeunit_ffi.erl"
DEBUG compile{package=gleeunit}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleeunit/src/gleeunit_progress.erl"
DEBUG compile{package=gleeunit}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleeunit/src/gleeunit@should.erl"
DEBUG compile{package=gleeunit}: skipping_unchanged_native_file_unchanged file="/Users/Neilerino/Programming/test_gleam/build/packages/gleeunit/src/gleeunit.erl"
TRACE compile{package=gleeunit}: writing_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/gleeunit/ebin/gleeunit.app"
DEBUG compile{package=gleeunit}: skipping_entrypoint_generation
DEBUG compile{package=gleeunit}: no_erlang_to_compile
TRACE compile{package=test_gleam}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/_gleam_artefacts/test_gleam.cache_meta"
TRACE compile{package=test_gleam}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/src/test_gleam.gleam"
DEBUG compile{package=test_gleam}:load: cache_stale name="test_gleam"
TRACE compile{package=test_gleam}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/_gleam_artefacts/other_file.cache_meta"
TRACE compile{package=test_gleam}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/src/other_file.gleam"
DEBUG compile{package=test_gleam}:load: cache_stale name="other_file"
TRACE compile{package=test_gleam}:load: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/_gleam_artefacts/test_gleam_test.cache_meta"
DEBUG compile{package=test_gleam}: module_to_be_compiled module=other_file
DEBUG compile{package=test_gleam}: module_to_be_compiled module=test_gleam
DEBUG compile{package=test_gleam}: module_to_load_from_cache module=test_gleam_test
TRACE compile{package=test_gleam}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/_gleam_artefacts/test_gleam_test.cache"
TRACE compile{package=test_gleam}: reading_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/_gleam_artefacts/test_gleam_test.cache_warnings"
  Compiling test_gleam
 INFO compile{package=test_gleam}: analysing_modules count=2
DEBUG compile{package=test_gleam}: Type checking module="other_file"
DEBUG compile{package=test_gleam}: built glob set; 1 literals, 0 basenames, 0 extensions, 1 prefixes, 0 suffixes, 0 required extensions, 0 regexes
DEBUG compile{package=test_gleam}: built glob set; 1 literals, 0 basenames, 0 extensions, 1 prefixes, 0 suffixes, 0 required extensions, 0 regexes
DEBUG compile{package=test_gleam}: Type checking module="test_gleam"
DEBUG compile{package=test_gleam}: built glob set; 1 literals, 0 basenames, 0 extensions, 1 prefixes, 0 suffixes, 0 required extensions, 0 regexes
DEBUG compile{package=test_gleam}: performing_code_generation
DEBUG compile{package=test_gleam}: copying_native_source_files
TRACE compile{package=test_gleam}: reading_directory path="/Users/Neilerino/Programming/test_gleam/src"
TRACE compile{package=test_gleam}: reading_directory path="/Users/Neilerino/Programming/test_gleam/test"
TRACE compile{package=test_gleam}: writing_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/ebin/test_gleam.app"
DEBUG compile{package=test_gleam}: erlang_entrypoint_already_exists
DEBUG compile{package=test_gleam}: Generated Erlang module name="other_file.erl"
TRACE compile{package=test_gleam}: writing_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/_gleam_artefacts/other_file.erl"
DEBUG compile{package=test_gleam}: Generated Erlang header name="other_file_Test.hrl"
TRACE compile{package=test_gleam}: writing_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/include/other_file_Test.hrl"
DEBUG compile{package=test_gleam}: Generated Erlang module name="test_gleam.erl"
TRACE compile{package=test_gleam}: writing_file path="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/_gleam_artefacts/test_gleam.erl"
DEBUG compile{package=test_gleam}: compiling_erlang
TRACE compile{package=test_gleam}: command_exec program="escript" args="/Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/_gleam_artefacts/gleam@@compile.erl --lib /Users/Neilerino/Programming/test_gleam/build/dev/erlang --out /Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/ebin /Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/_gleam_artefacts/other_file.erl /Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/_gleam_artefacts/test_gleam.erl" env=[] cwd=None
{compiling,"/Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/_gleam_artefacts/test_gleam.erl"}
{compiling,"/Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/_gleam_artefacts/other_file.erl"}
/Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/_gleam_artefacts/test_gleam.erl:12:37: illegal guard expression
%   12|             {test, <<"test"/utf8>>, fun other_file:add_one/1}
%     |                                     ^

{failed,"/Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/_gleam_artefacts/test_gleam.erl"}
{compiled,"/Users/Neilerino/Programming/test_gleam/build/dev/erlang/test_gleam/ebin/other_file.beam"}
ERROR Failed error=ShellCommand { program: "escript", err: None }
error: Shell command failure

There was a problem when running the shell command `escript`.

If I remove the function from the records params like this, I'm able to compile and run without issues.

pub type Test {
  Test(input_string: String)
}
lpil commented 1 month ago

Thank you

GearsDatapacks commented 1 month ago

Looks like this only occurs if you're using a constant, since the value is essentially inlined, and I guess erlang doesn't like functions in guard clauses, even if they aren't being called. Probably the easiest fix for this would be to assign the value to a temporary variable beforehand and just do the case on that. The equivalent of (this compiles):

// test_gleam.gleam
import gleam/io
import other_file

pub fn main() {
  let case_var = ["test", "test2"]
  let temp = other_file.case_test
  case case_var {
    [head, ..] if head == temp.input_string -> {
      io.println("test")
    }
    _ -> {
      io.println("not test")
    }
  }
}
GearsDatapacks commented 1 month ago

Also, I believe this is the same issue as #3069

lpil commented 1 month ago

Thank you @GearsDatapacks !