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

Substitute type parameters when type checking calls #915

Closed
lars-reimann opened this issue Feb 22, 2024 · 2 comments · Fixed by #923
Closed

Substitute type parameters when type checking calls #915

lars-reimann opened this issue Feb 22, 2024 · 2 comments · Fixed by #923
Assignees
Labels
enhancement 💡 New feature or request released Included in a release validation ✔️ Improved or new static checks
Milestone

Comments

@lars-reimann
Copy link
Member

lars-reimann commented Feb 22, 2024

Is your feature request related to a problem?

For calls of functions with type parameters, the type checker might show incorrect errors:

fun f<T>(p: (a: T) -> b: String)

pipeline myPipeline {
    // Expected type '(a: T) -> (b: String)' but got '(a: String) -> (result: String)'
    f((a: String) -> a);
}

That's because T has the upper bound Any? and, thus, String is not generally a supertype of T (comparing the parameter types).

Desired solution

Once #861 is done, we also need to substitute type parameters when checking argument types vs. parameter types. Since we need these substitutions multiple times (for each parameter and for the call results in #861), we might also consider caching the substitutions for each call.

Possible alternatives (optional)

No response

Screenshots (optional)

No response

Additional Context (optional)

No response

@lars-reimann lars-reimann added the enhancement 💡 New feature or request label Feb 22, 2024
@lars-reimann lars-reimann added this to DSL Feb 22, 2024
@github-project-automation github-project-automation bot moved this to Backlog in DSL Feb 22, 2024
@lars-reimann lars-reimann self-assigned this Feb 22, 2024
@lars-reimann lars-reimann moved this from Backlog to Todo in DSL Feb 22, 2024
@lars-reimann lars-reimann added this to the v0.8.0 milestone Feb 22, 2024
@lars-reimann lars-reimann added the validation ✔️ Improved or new static checks label Feb 22, 2024
lars-reimann added a commit that referenced this issue Feb 22, 2024
Related to #915

### Summary of Changes

As described in #915, the code

```
fun f<T>(p: (a: T) -> b: String)

pipeline myPipeline {
    // Expected type '(a: T) -> (b: String)' but got '(a: String) -> (result: String)'
    f((a: Int) -> a);
}
```

currently shows an error due to a parameter mismatch (contravariant
context). In a covariant context (e.g. for results), however, no such
error is shown. That's because when checking whether a type `T1` can be
assigned to a type `T2`, we used to replace a type parameter type as
`T1` with its **upper** bound (strict) and as `T2` with its upper bound
(lenient).

We now instead replace a type parameter as `T1` with its **lower** bound
(lenient). This simply checks whether there are any substitutions for
`T1` that could let the subtype relation become true.
@lars-reimann
Copy link
Member Author

lars-reimann commented Feb 25, 2024

This also affects the check for default values of parameters:

fun f<T1, T2 sub Number>(
    p1: T1,
    p2: T2 = p1, // Not OK - f(p1 = null)
    p3: T1 = p2, // Not OK
)

@lars-reimann lars-reimann moved this from Todo to In Progress in DSL Feb 26, 2024
@lars-reimann lars-reimann linked a pull request Feb 26, 2024 that will close this issue
lars-reimann added a commit that referenced this issue Feb 26, 2024
Closes #915

### Summary of Changes

* Substitute type parameter when type checking calls.
* Remove lenient type checking mode. We now use the strict mode
everywhere, which means when calling `isSubtypeOf(type, other)` that the
upper bound of `type` must be a subtype of the lower bound of `other`.
@github-project-automation github-project-automation bot moved this from In Progress to ✔️ Done in DSL Feb 26, 2024
lars-reimann pushed a commit that referenced this issue Feb 26, 2024
## [0.8.0](v0.7.0...v0.8.0) (2024-02-26)

### Features

* check the runner version to be compatible ([#888](#888)) ([83378a3](83378a3)), closes [#880](#880)
* check type parameter bounds for default values and named types ([#919](#919)) ([7003ea6](7003ea6)), closes [#614](#614)
* clamp default values of parameter types to upper bound ([#921](#921)) ([76ad869](76ad869))
* compute highest common subtype ([#901](#901)) ([5630a9f](5630a9f)), closes [#860](#860)
* compute type parameters for calls ([#920](#920)) ([35dc826](35dc826)), closes [#861](#861)
* consider nullability of upper type parameter bound in various checks ([#892](#892)) ([940515a](940515a))
* constraints for segments ([#911](#911)) ([e57f886](e57f886)), closes [#903](#903)
* EDA on pipeline Tables ([#834](#834)) ([f42c9aa](f42c9aa))
* error if parent type is nullable ([#891](#891)) ([add650d](add650d))
* escape characters in string conversion of string constants ([#908](#908)) ([72a9c3c](72a9c3c)), closes [#904](#904)
* format upper bound of type parameters ([#898](#898)) ([9d6ce28](9d6ce28))
* handle invariant/covariant type parameters when computing lowest common supertype ([#868](#868)) ([4d6cb4e](4d6cb4e)), closes [#860](#860) [#861](#861)
* improve handling of subclasses of lists/maps ([#890](#890)) ([bb0c94b](bb0c94b))
* improvements to constraints ([#896](#896)) ([b81bef9](b81bef9)), closes [#18](#18) [#860](#860) [#18](#18)
* include enum name in string conversion of enum variant types ([#907](#907)) ([1f6502e](1f6502e)), closes [#902](#902)
* scoping for member accesses if receiver has type parameter type ([#889](#889)) ([1277bd1](1277bd1))
* shorter message if runner is started but files have errors ([#912](#912)) ([b611b44](b611b44)), closes [#910](#910)
* simplify union types containing type parameter types disregarding entry order ([#894](#894)) ([cf6e77e](cf6e77e))
* singular type is its own lowest common supertype ([#893](#893)) ([79d611d](79d611d))
* substitute type parameter when type checking calls ([#923](#923)) ([2e09306](2e09306)), closes [#915](#915)
* substitute type parameters when checking overridden members ([#922](#922)) ([0e657cf](0e657cf)), closes [#917](#917)
* update to `safe-ds-runner` v0.7.0 ([#906](#906)) ([070f406](070f406))
* use bounds of type system where possible ([#899](#899)) ([cf92762](cf92762))

### Bug Fixes

* lenient type checking involving type parameter types ([#916](#916)) ([b9d3641](b9d3641)), closes [#915](#915) [#915](#915)
* runner startup silent failure ([#914](#914)) ([8812944](8812944)), closes [#909](#909)
* save dirty files before running pipeline ([#918](#918)) ([4302ca6](4302ca6))
* simplification of union types ([#897](#897)) ([4c577a3](4c577a3))
@lars-reimann
Copy link
Member Author

🎉 This issue has been resolved in version 0.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lars-reimann lars-reimann added the released Included in a release label Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 💡 New feature or request released Included in a release validation ✔️ Improved or new static checks
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant