Skip to content

Conversation

@Efnilite
Copy link
Member

@Efnilite Efnilite commented Mar 30, 2025

Description

Adds function overloading.

Function overloading allows two functions with the same name to be registered, as long as

  • their parameter types differ, or
  • the amount of arguments differ.

An example:

function overloaded(x: int, y: int) :: int:
	return 1

function overloaded(x: int, y: int, z: int) :: int:
	return 2

function overloaded(x: text, y: text) :: int:
	return 3

function overloaded(x: text, y: int, z: int) :: int:
	return 4

FunctionRegistry

Description
To accomplish this, a new FunctionRegistry class has been added, which is only visible to the function package. This holds all signatures and functions by a namespace. A namespace is either the global namespace, for global functions, or a script, in which local functions can be registered.

Functions and signatures are differentiated by a FunctionIdentifier, which holds the function's name and the types of its arguments.

Why are the methods in the Functions class not deprecated?
In the future, I plan on adding function parameter specification by name, e.g. location(x=10,y=10,z=10,world="world"). When that has been added, there will, in my opinion, be enough future-proofing, thus the FunctionRegistry class can replace the Functions class' functionality. Overloaded functions will not be visible to Functions.

Behaviour

When a function has an ambiguous type in one of its arguments, it will attempt to match based on the other arguments.
Therefore, overloaded(1, {_none}) and overloaded({_none}, 2) will still call the correct overloaded, as the function overloaded(int, int) is the only one that can be matched here.

When a function has multiple implementations, and it can't be decided which one to use (due to variables for example), a parse-time error will be thrown.

image

Like other languages, functions cannot be differentiated by return type.


Target Minecraft Versions: any
Requirements: none
Related Issues: #1185, #2993

@Efnilite Efnilite added feature Pull request adding a new feature. functions Related to functions labels Mar 30, 2025
@Efnilite Efnilite requested a review from Copilot March 30, 2025 14:47
@Efnilite Efnilite requested review from a team as code owners March 30, 2025 14:47
@Efnilite Efnilite requested review from UnderscoreTud and sovdeeth and removed request for a team March 30, 2025 14:47

This comment was marked as resolved.

@Efnilite Efnilite requested a review from Copilot March 30, 2025 14:50

This comment was marked as resolved.

@Efnilite Efnilite added the 2.12 Targeting a 2.12.X version release. Project ID: 7 label Mar 31, 2025
@sovdeeth
Copy link
Member

sovdeeth commented Apr 1, 2025

"Try clarifying the type of the arguments"

How?

@Efnilite
Copy link
Member Author

Efnilite commented Apr 1, 2025

"Try clarifying the type of the arguments"

How?

I was thinking literal type clarification but I guess that's only for literals

@sovdeeth
Copy link
Member

sovdeeth commented Apr 1, 2025

"Try clarifying the type of the arguments"

How?

I was thinking literal type clarification but I guess that's only for literals

You could evaluate at runtime, which could be very flexible but also possibly confusing to users in some cases.
store the candidates and pick at runtime

@Efnilite
Copy link
Member Author

Efnilite commented Apr 2, 2025

I think I prefer a more limited system that errors at parse time over one that may cause runtime errors. Wdyt?

@Burbulinis
Copy link
Member

Burbulinis commented Apr 2, 2025

Why not just use ExprValueWithin to clarify the type?

@Efnilite Efnilite requested a review from APickledWalrus June 26, 2025 18:04
@github-project-automation github-project-automation bot moved this from In Review to Awaiting Merge in 2.12 Releases Jun 29, 2025
@Efnilite Efnilite added the don't merge me !! For pull requests that should not be merged due to some outstanding dispute, conflict or dependency. label Jun 30, 2025
@Efnilite Efnilite added feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. and removed don't merge me !! For pull requests that should not be merged due to some outstanding dispute, conflict or dependency. labels Jun 30, 2025
@skriptlang-automation skriptlang-automation bot removed the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label Jun 30, 2025
@Efnilite Efnilite added the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label Jun 30, 2025
@skriptlang-automation skriptlang-automation bot removed the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label Jul 1, 2025
@Efnilite Efnilite added the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label Jul 1, 2025
@skriptlang-automation skriptlang-automation bot removed the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label Jul 1, 2025
@APickledWalrus APickledWalrus merged commit 9806eef into dev/feature Jul 1, 2025
6 checks passed
@github-project-automation github-project-automation bot moved this from Awaiting Merge to Done in 2.12 Releases Jul 1, 2025
@skriptlang-automation skriptlang-automation bot added the completed The issue has been fully resolved and the change will be in the next Skript update. label Jul 1, 2025
@Efnilite Efnilite deleted the feature/fun-overloading branch July 3, 2025 12:28
Burbulinis pushed a commit to Burbulinis/Skript that referenced this pull request Jul 9, 2025
erenkarakal pushed a commit to erenkarakal/Skript that referenced this pull request Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.12 Targeting a 2.12.X version release. Project ID: 7 completed The issue has been fully resolved and the change will be in the next Skript update. feature Pull request adding a new feature. functions Related to functions

Projects

No open projects
Status: Done - Released

Development

Successfully merging this pull request may close these issues.

Suggestion: Optional function parameter Allow overloading of functions

7 participants