roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.4k stars 309 forks source link

Compiler panic if `dec` number literal doesn't have a decimal point #2845

Closed rtfeldman closed 2 years ago

rtfeldman commented 2 years ago

These both work as expected:

» 3f64

3 : F64
» 3.0dec

3 : Dec
» x : Dec
… x = 3
… x

3 : Dec

However, this crashes the compiler:

» 3dec
thread '<unnamed>' panicked at 'Invalid decimal for float literal = 3dec. TODO: Make this a nice, user-friendly error message', compiler/mono/src/ir.rs:3180:37

The panic is in monomorphization, but the problem is most likely earlier than that.

rtfeldman commented 2 years ago

It's possible that https://github.com/rtfeldman/roc/issues/2846 and https://github.com/rtfeldman/roc/issues/2844 may be related to this.

ayazhafiz commented 2 years ago

This is also a good first issue. The problem lies here:

https://github.com/rtfeldman/roc/blob/157c77962ec7d7e2fd8c966f8ea4afa37fec7261/compiler/can/src/num.rs#L213-L222

https://github.com/rtfeldman/roc/pull/2800/files fixed a similar bug (but didn't go far enough :) ), so that may be helpful.

This is a nice issue in that it will expose you to a few different pipelines of the compiler

drakebennion commented 2 years ago

Can I take this one?

rtfeldman commented 2 years ago

Absolutely! Feel free to ask on Zulip if you have any questions or get stuck on anything! 😃

rtfeldman commented 2 years ago

Fixed in https://github.com/rtfeldman/roc/pull/3081