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

AoC PR: Automatic select t.0/t.1,... instead of t.values.0, t.values.1, ... #2392

Merged
merged 5 commits into from
Dec 20, 2023

Conversation

fridis
Copy link
Member

@fridis fridis commented Dec 19, 2023

This simplifies the code to access the elements of, e.g., a tuple where it is not possible to write t.2 instead of t.values.2.

This syntax sugar comes with the following restrictions:

  • it is only applicable to types declared in library features

  • the result type of the feature must be an open type parameter

  • there must not be any function arguments in the call

  • there must be exactly one such feature visible

For this, I also had to fix type inference from actual args in case actuals get replaced.

This fixes a bug that was revealed by automatically calling features with open type parameters (eg., t.0 instead of t.values.0 in tuples): When the actual expression gets replaced by something else, the type inference still used the original expression resulting in potentially wrong types being inferred.

This patch no longer stores the actual argument that was found, but instead stores the call that was found. To determine the actual type, the actual is taken form the call resulting in the new actual in case it was replaced during resolveTypes or syntax sugar phases.

This also cleans up the somewhat clumsy check to prevent infinite recursion and uses a simple flag instead.

This simplifies the code to access the elements of, e.g., a tuple where it is
not possible to write `t.2` instead of `t.values.2`.

This syntax sugar comes with the following restrictions:

- it is only applicable to types declared in library features

- the result type of the feature must be an open type parameter

- there must not be any function arguments in the call

- there must be exactly one such feature visible
This fixes a bug that was revealed by automatically calling features with open
type parameters (eg., t.0 instead of t.values.0 in tuples): When the actual
expression gets replaced by something else, the type inference still used the
original expression resulting in potentially wrong types being inferred.

This patch no longer stores the actual argument that was found, but instead
stores the call that was found.  To determine the actual type, the actual is
taken form the call resulting in the new actual in case it was replaced during
resolveTypes or syntax sugar phases.

This also cleans up the somewhat clumsy check to prevent infinite recursion and
uses a simple flag instead.
@fridis fridis marked this pull request as draft December 19, 2023 15:19
@fridis fridis marked this pull request as ready for review December 19, 2023 15:25
@fridis fridis changed the title Automatic select t.0/t.1,... instead of t.values.0, t.values.1, ... AoC PR: Automatic select t.0/t.1,... instead of t.values.0, t.values.1, ... Dec 19, 2023
@michaellilltokiwa
Copy link
Member

Cool. I also tried implementing t.0 as shorthand for t.values.0 a few weeks ago but looking at this patch my efforts where destined to fail... :-)

@michaellilltokiwa michaellilltokiwa merged commit 7ddfbe5 into main Dec 20, 2023
5 checks passed
@fridis
Copy link
Member Author

fridis commented Dec 20, 2023

Cool. I also tried implementing t.0 as shorthand for t.values.0 a few weeks ago but looking at this patch my efforts where destined to fail... :-)

Well, the change in Call.java was not the problem, the problem was fixing the existing bug in Impl.java...

@maxteufel maxteufel deleted the automatic_select branch January 15, 2024 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants