effekt icon indicating copy to clipboard operation
effekt copied to clipboard

Builtin get and set operations cannot be shadowed when using dot notation

Open IR0NSIGHT opened this issue 1 year ago • 2 comments

linter bug: Unbox requires a boxed type, but got Array[Int].effekt minified example:

def test(arr: Array[Int]) = {
	arr.put(3,12)
}

IR0NSIGHT avatar Dec 04 '23 14:12 IR0NSIGHT

Hi @IR0NSIGHT,

thanks for reporting. If you want a temporary workaround, just use put(arr, 3, 12) instead :)

I'm running into the same problem in Advent of Code. I can also trigger the error message when using get. I think the culprit is the get and put builtins which [somehow] take precedence over user-defined functions when used with dot-syntax.

Here's the definition of get and set (originating from TState above) https://github.com/effekt-lang/effekt/blob/4d2e4868c99482d9c1fa327c7c542dc27e2c344f/effekt/shared/src/main/scala/effekt/symbols/builtins.scala#L85-L86

jiribenes avatar Dec 04 '23 14:12 jiribenes

Simple reproduction which doesn't need the import of mutable/array:

def get(x: Int): Int = x + 42

def main() = {
    val result = 100.get
    println(result)
}

produces the error:

[error] issue.effekt:4:18: Unbox requires a boxed type, but got Int.
    val result = 100.get
                 ^^^

which originates in Typer: https://github.com/effekt-lang/effekt/blob/4d2e4868c99482d9c1fa327c7c542dc27e2c344f/effekt/shared/src/main/scala/effekt/Typer.scala#L450

However, calling get as a function directly (without dot notation) works:

def get(x: Int): Int = x + 42

def main() = {
    val result = get(100)
    println(result) // prints 142
}

jiribenes avatar Dec 04 '23 14:12 jiribenes

Is this requirement still necessary with #305, @b-studios? It would be nice to "release" get and put to be overloaded by the users.

jiribenes avatar Mar 22 '24 09:03 jiribenes