-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: substitute type parameters for lambda parameters (#1050)
Closes #1047 ### Summary of Changes Type of lambda parameters can be inferred from the context. Previously, however, type parameter types that were contained in the inferred type were not substituted. Now, they also get inferred from the context.
- Loading branch information
1 parent
db0c5d7
commit 46145dd
Showing
7 changed files
with
307 additions
and
145 deletions.
There are no files selected for viewing
342 changes: 205 additions & 137 deletions
342
packages/safe-ds-lang/src/language/typing/safe-ds-type-computer.ts
Large diffs are not rendered by default.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
...ions/parameters/of block lambdas/that are passed as arguments/with type parameters.sdsdev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package tests.typing.declarations.parameters.ofBlockLambdas.thatArePassedAsArguments.withTypeParameters | ||
|
||
class MySuperclass<T> { | ||
@Pure fun myInheritedMethod(callback: (p: T) -> ()) | ||
} | ||
|
||
class MyClass<T>(param: T) sub MySuperclass<T> { | ||
@Pure fun myMethod(callback: (p: T) -> ()) | ||
} | ||
|
||
@Pure fun myFunction<T>(p: T, callback: (p: T) -> ()) | ||
|
||
segment mySegment() { | ||
// $TEST$ serialization literal<1> | ||
MyClass(1).myMethod((»p«) {}); | ||
|
||
// $TEST$ serialization literal<1> | ||
MyClass(1).myInheritedMethod((»p«) {}); | ||
|
||
// $TEST$ serialization literal<1> | ||
myFunction(1, (»p«) {}); | ||
} |
22 changes: 22 additions & 0 deletions
22
...parameters/of expression lambdas/that are passed as arguments/with type parameters.sdsdev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package tests.typing.declarations.parameters.ofExpressionLambdas.thatArePassedAsArguments.withTypeParameters | ||
|
||
class MySuperclass<T> { | ||
@Pure fun myInheritedMethod(callback: (p: T) -> ()) | ||
} | ||
|
||
class MyClass<T>(param: T) sub MySuperclass<T> { | ||
@Pure fun myMethod(callback: (p: T) -> ()) | ||
} | ||
|
||
@Pure fun myFunction<T>(p: T, callback: (p: T) -> ()) | ||
|
||
segment mySegment() { | ||
// $TEST$ serialization literal<1> | ||
MyClass(1).myMethod((»p«) -> ""); | ||
|
||
// $TEST$ serialization literal<1> | ||
MyClass(1).myInheritedMethod((»p«) -> ""); | ||
|
||
// $TEST$ serialization literal<1> | ||
myFunction(1, (»p«) -> ""); | ||
} |
8 changes: 4 additions & 4 deletions
8
...tests/resources/typing/expressions/block lambdas/that are passed as arguments/main.sdsdev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...typing/expressions/block lambdas/that are passed as arguments/with type parameters.sdsdev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package tests.typing.expressions.blockLambdas.thatArePassedAsArguments.withTypeParameters | ||
|
||
class MySuperclass<T> { | ||
@Pure fun myInheritedMethod(callback: (p: T) -> ()) | ||
} | ||
|
||
class MyClass<T>(param: T) sub MySuperclass<T> { | ||
@Pure fun myMethod(callback: (p: T) -> ()) | ||
} | ||
|
||
@Pure fun myFunction<T>(p: T, id: (p: T) -> (r: T)) | ||
|
||
segment mySegment() { | ||
// $TEST$ serialization (p: literal<1>) -> (r: literal<1>) | ||
MyClass(1).myMethod(»(p) { | ||
yield r = p; | ||
}«); | ||
|
||
// $TEST$ serialization (p: literal<1>) -> (r: literal<1>) | ||
MyClass(1).myInheritedMethod(»(p) { | ||
yield r = p; | ||
}«); | ||
|
||
// $TEST$ serialization (p: literal<1>) -> (r: literal<1>) | ||
myFunction(1, »(p) { | ||
yield r = p; | ||
}«); | ||
} |
8 changes: 4 additions & 4 deletions
8
.../resources/typing/expressions/expression lambdas/that are passed as arguments/main.sdsdev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...g/expressions/expression lambdas/that are passed as arguments/with type parameters.sdsdev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package tests.typing.expressions.expressionLambdas.thatArePassedAsArguments.withTypeParameters | ||
|
||
class MySuperclass<T> { | ||
@Pure fun myInheritedMethod(callback: (p: T) -> ()) | ||
} | ||
|
||
class MyClass<T>(param: T) sub MySuperclass<T> { | ||
@Pure fun myMethod(callback: (p: T) -> ()) | ||
} | ||
|
||
@Pure fun myFunction<T>(p: T, id: (p: T) -> (r: T)) | ||
|
||
segment mySegment() { | ||
// $TEST$ serialization (p: literal<1>) -> (result: literal<1>) | ||
MyClass(1).myMethod(»(p) -> p«); | ||
|
||
// $TEST$ serialization (p: literal<1>) -> (result: literal<1>) | ||
MyClass(1).myInheritedMethod(»(p) -> p«); | ||
|
||
// $TEST$ serialization (p: literal<1>) -> (result: literal<1>) | ||
myFunction(1, »(p) -> p«); | ||
} |