gleam icon indicating copy to clipboard operation
gleam copied to clipboard

Compilation error for JS target when an unused package has a feature not supported in the JS target.

Open Enderchief opened this issue 5 months ago • 2 comments

This issue is an extension of #2324.

Problem

When building for the JavaScript target and a package uses a BitArray feature that is not supported for the JavaScript target compilation fails.

Minimal recreation steps

(as I performed along with the output I got)

$ gleam --version
gleam 0.34.1

$ gleam new multitarget
Your Gleam project multitarget has been successfully created.
The project can be compiled and tested by running these commands:

	cd multitarget
	gleam test

$ cd multitarget

$ gleam add gleam_crypto 

$ gleam build --target=js
  Compiling gleam_crypto
error: Unsupported feature for compilation target
   ┌─ /pathtodir/multitarget/build/packages/gleam_crypto/src/gleam/crypto.gleam:48:10
   │
48 │     <<x, left:bits>>, <<y, right:bits>> -> {
   │          ^^^^^^^^^

This bit array segment option in patterns is not supported for JavaScript compilation.

Expected Behaviour

Package should compile with no errors as the target does not use gleam_crypto. If I am not importing a package within the JavaScript target either explicitly (importing it using @target(javascript) or otherwise (importing a package using @target(javascript) that imports this package), it should not build / error out.

Enderchief avatar Jan 22 '24 05:01 Enderchief

I am reconsidering this issue. Perhaps it should be closed an a different issue needs to be solved. The eventual goal is to have "Full bit array support" source: Gleam Tour. If that becomes the case, this would not be a problem. My concern is, are there other features that are not supported in one target but supported in the other? If so what are those and those should be fixed.

Enderchief avatar Jan 22 '24 06:01 Enderchief

Let's go for both as I'm sure it will be a long time before we can support all bit syntax on JavaScript.

lpil avatar Jan 23 '24 13:01 lpil