Assertion failed exception


When I use this code

let importantNumbers = [42, 2001, 31459];
let [answer, yearWeMakeContact, pi] = importantNumbers;

I get this error

Fatal error: exception File "", line 218, characters 4-10: Assertion failed

I think it’s related to this bug in Bucklescript, but I just want to make sure I’m on the right path.


Compiles and even runs in the playground. But the compiler gives me a warning, because your destructuring kind of supposes the list always has at least 3 elements, which, of course, the comliper cannot prove. Now, if you went with tuples…


let importantNumbers = (42, 2001, 314159);
let (answer, yearWeMakeContact, pi) = importantNumbers;


Oh yeah, absolutely. This was about experimentation, not using it in an application.

I get the warning underline in VS Code, but when I try to compile, I get that weird error. Even weirder, the line mentioned in the error is wildly incorrect. It’s not on line 218, but 840.


Just dropped those lines of code into a separate file and got more semantic errors in the console.

  You forgot to handle a possible case here, for example: 
Fatal error: exception File "", line 218, characters 4-10: Assertion failed

Ultimate fatal error is the same, but I’m at least seeing the correct warning. I now understand that the line error is line 218 in the file.


With that knowledge, I checked Bucklescript’s code and it’s obvious that they are aware of the problem. They reference the two pertinent bugs. I suppose I just have to be aware of what causes this and try to avoid it for now.

| _ ->
    (* This could happen see #2474*)
    (* #3595 
    TODO: FIXME later
    assert false
    (* {
      export_list = meta.exports;
      export_set = meta.export_idents;
      export_map = Ident_map.empty ;
      (** not used in code generation, mostly used
          for store some information in cmj files *)
      groups = [Nop lam] ;
      (* all code to be compiled later = original code + rebound coercions *)
    , meta *)


I’m actually unable to reproduce this error, see e.g.

The output JS doesn’t look like it can throw an ‘Assertion failed’ error. I’m fairly sure that’s coming from somewhere else. I’d recommend isolating and dropping the above two lines into a separate project to convince yourself :slight_smile:


I indeed did that. I still get the console error. I don’t get it anywhere else, though, as you discovered in the online playground.


Oh! My apologies. I just tried it out. This exception is being thrown by the BuckleScript compiler itself, not any in-project code. So, definitely a BuckleScript bug.