Repository navigation
Closed
Labels
Description
Whenever there is an option-like variant being introduced, such as:
module NotOption = {
type t<'a> = None | Some('a)
}The constructors generated do not match the patterns:
let a = NotOption.None // 0, ok..
let b = NotOption.Some(3) // 3, should generate { _0: 3 }
let f = notOption => switch notOption {
| NotOption.None => (...) // pattern compiles to an undefined check, should be checking 0
| NotOption.Some(_) => (...)
}Adding a type equality, such as below, will also result in code that compiles but emits incorrect code at runtime.
module NotOption = {
type t<'a> = option<'a> = None | Some('a)
}
let a = NotOption.None // 0, not undefined
let b = NotOption.Some(3) // 3In more detail, we have:
module NotOption = {
type t<'a> = None | Some('a)
}
let a = NotOption.None // 0
let b = NotOption.Some(1) // 1
let c = { open NotOption; None } // undefined
let d = { open NotOption; Some(1) } // 1
// changing the order doesn't resolve the issue
module TotallyNotOption = {
type t<'a> = Some('a) | None
}
let e = TotallyNotOption.None // 0
let f = TotallyNotOption.Some(1) // 1
let g = { open TotallyNotOption; None } // undefined
let h = { open TotallyNotOption; Some(1) } // 1
// adding a third variant resolves this issue
module NotOption2 = {
type t<'a> = None | Some('a) | Bogus
}
let i = NotOption2.None // 0
let j = NotOption2.Some(1) // { _0: 1 }
let k = { open NotOption2; None } // 0
let l = { open NotOption2; Some(1) } // { _0: 1 }
Activity
bobzhang commentedon Jun 7, 2021
this seems to be a bug, but in general it is not recommended to redefine built in types
bobzhang commentedon Jun 8, 2021
@diaozheng999 will send a fix and cherry pick to 9.1
fix #5169
Merge pull request #5174 from rescript-lang/fix_5169
fix #5169
fix #5169