Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
IR0NSIGHT opened this issue Dec 4, 2023 · 3 comments · Fixed by #424
Closed

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

IR0NSIGHT opened this issue Dec 4, 2023 · 3 comments · Fixed by #424
Labels
bug Something isn't working

Comments

@IR0NSIGHT
Copy link
Collaborator

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

def test(arr: Array[Int]) = {
	arr.put(3,12)
}
@IR0NSIGHT IR0NSIGHT added the bug Something isn't working label Dec 4, 2023
@jiribenes
Copy link
Contributor

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)

"get" -> TState.get,
"put" -> TState.put

@jiribenes jiribenes changed the title Unbox requires a boxed type, but got Array[Int].effekt Builtin get and set operations cannot be shadowed when using dot notation Dec 4, 2023
@jiribenes
Copy link
Contributor

jiribenes commented Dec 4, 2023

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:

Context.abort(pretty"Unbox requires a boxed type, but got $vtpe.")

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants