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

feat: do not check whether optional type parameters of classes can be inferred #1090

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ export const typeParameterMustHaveSufficientContext = (node: SdsTypeParameter, a
}
/* c8 ignore stop */

// Classes without constructor can only be used as named types, where type arguments are manifest
if (isSdsClass(containingCallable) && !containingCallable.parameterList) {
// Optional type parameters of classes get initialized to their default value if there is insufficient context in
// the constructor. Elsewhere, the class might be used as a named type, where type arguments are manifest, so having
// the type parameter is beneficial. This is not the case for functions, where type parameters only get inferred.
//
// Classes without constructor can only be used as named types, where type arguments are manifest.
if (isSdsClass(containingCallable) && (TypeParameter.isOptional(node) || !containingCallable.parameterList)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class MyClass8<»T«>(param: () -> (r: (p: T) -> ()))
class MyClass9<»T«>(param: union<T>)
// $TEST$ error "Insufficient context to infer this type parameter."
class MyClass10<»T«>(param: union<T, Int>)
// $TEST$ no error "Insufficient context to infer this type parameter."
class MyClass11<»T« = Int>()

// $TEST$ error "Insufficient context to infer this type parameter."
fun myFunction1<»T« sub Int>()
Expand All @@ -39,3 +41,5 @@ fun myFunction6<»T«>(param: () -> (r: (p: T) -> ()))
fun myFunction7<»T«>(param: union<T>)
// $TEST$ error "Insufficient context to infer this type parameter."
fun myFunction8<»T«>(param: union<T, Int>)
// $TEST$ error "Insufficient context to infer this type parameter."
fun myFunction9<»T« = Int>()