Skip to content

[TypeChecker] SE-0347: Perform syntactic diagnostics after inference #62094

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

Merged
merged 1 commit into from
Nov 14, 2022
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
2 changes: 2 additions & 0 deletions lib/Sema/TypeCheckConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,8 @@ Type TypeChecker::typeCheckParameterDefault(Expr *&defaultValue,
cs.applySolution(solution);

if (auto result = cs.applySolution(solution, defaultExprTarget)) {
// Perform syntactic diagnostics on the type-checked target.
performSyntacticDiagnosticsForTarget(*result, /*isExprStmt=*/false);
defaultValue = result->getAsExpr();
return defaultValue->getType();
}
Expand Down
15 changes: 14 additions & 1 deletion test/Constraints/type_inference_from_default_exprs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ protocol StorageType {
var identifier: String { get }
}

class Storage {
class Storage { // expected-note {{class 'Storage' is not public}}
}

extension Storage {
Expand Down Expand Up @@ -253,3 +253,16 @@ struct S61061_2<T> where T:Hashable {
struct S61061_3<T> where T:Hashable {
init(x:[(T, T)] = [(1, 1)]) {} // OK
}

// https://github.com/apple/swift/issues/62025
// Syntactic checks are not run on the default argument expressions
public struct MyStruct {} // expected-note {{initializer 'init()' is not public}}
public func issue62025_with_init<T>(_: T = MyStruct()) {}
// expected-error@-1 {{initializer 'init()' is internal and cannot be referenced from a default argument value}}
public func issue62025_with_type<T>(_: T = Storage.self) {}
// expected-error@-1 {{class 'Storage' is internal and cannot be referenced from a default argument value}}
do {
func default_with_dup_keys<T>(_: T = ["a": 1, "a": 2]) {}
// expected-warning@-1 {{dictionary literal of type '[String : Int]' has duplicate entries for string literal key 'a'}}
// expected-note@-2 2 {{duplicate key declared here}}
}