-
-
Notifications
You must be signed in to change notification settings - Fork 154
Closed
Description
Code example causing compiler error
type Modification {
Create
Move(id : String, afterId : Maybe(String))
}
component Main {
fun render : Html {
let arr = processMoves([Modification.Move("1", Maybe.Nothing)])
<div>"Hello World!"</div>
}
fun processMoves(arr : Array(Modification.Move)) : Array(Modification.Move) {
arr
}
}Issue
Function processMoves() expects an array of explicitly the Modification.Move variant, however the compiler simplifies the parameter to accept the whole type (accepting all variants), instead of specific variant of the type.
I believe this should be allowed because my workaround would be to create a struct for passing parameters and returning the result, which then I would have to map back to the ADT variant anyway, so there's more of manual code.
Alternatively, the function processMoves() should be errored first on the parameter type, i.e. it should be explicitly explained that ADT variants are not allowed as types. This option is less preferrable but it would specify the limits of the system.
Error
░ ERROR (CALL_ARGUMENT_TYPE_MISMATCH) ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
The 1st argument to a function is causing a mismatch.
The function is expecting the 1st argument to be:
Array(Modification.Move)
Instead it is:
Array(Modification)
The call in question is here:
┌ Main.mint:8:15
├────────────────────────────────────────────────────────────────────
4│ }
5│
6│ component Main {
7│ fun render : Html {
8│ let arr = processMoves([Modification.Move("1", Maybe.Nothing)])
│ ⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃
9│
10│ <div>"Hello World!"</div>
11│ }
12│
Sandbox
https://mint-lang.com/sandbox/hRoQ-3GqY5xNhg

Metadata
Metadata
Assignees
Labels
No labels