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

[SR-12869] Inaccurate error message when assigning an (Int64, T) tuple to an (Int, T) value in a dictionary #55316

Closed
swift-ci opened this issue May 23, 2020 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-12869
Radar None
Original Reporter Angelastic (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51) in Xcode Version 11.4.1 (11E503a), macOS 10.15.4 (19E287)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, TypeChecker
Assignee Angelastic (JIRA)
Priority Medium

md5: af74e671cb985e8231e4b38cb7ecc2b2

Issue Description:

When assigning an (Int64, URL) literal to an (Int, URL) in a dictionary, I get the error:

'(Int64, URL)' is not convertible to '(Int, URL)?', tuples have a different number of elements

which is incorrect since the tuples have the same number of elements. I also get the more understandable error:

Cannot assign value of type '(Int64, URL)' to subscript of type '(Int, URL)'

When assigning the same tuple to a (Int, URL) variable not in a dictionary, I just get the latter error.

(Note, I happened to discover this with (Int, URL) tuples, but it still happens with String instead of URL, and presumedly any other type.)

var dict:[String:(Int, URL)] = [:]
        let bignum:Int64 = 1337
        if let url = URL(string: "http://bugs.swift.org") {
            dict["test"] = (bignum,url) //'(Int64, URL)' is not convertible to '(Int, URL)?', tuples have a different number of elements   Cannot assign value of type '(Int64, URL)' to subscript of type '(Int, URL)'
            var tuple:(Int,URL)
            tuple = (bignum,url) //Cannot assign value of type '(Int64, URL)' to subscript of type '(Int, URL)'
        }
@LucianoPAlmeida
Copy link
Collaborator

On the lastest snapshot it crashes the compiler 2020-05-21

While type-checking expression at [/Users/lucianoalmeida/Documents/Programming/Test Area/DynamicMamberTest/DynamicMamberTest/main.swift:82:5 - line:82:31] RangeText="dict["test"] = (bignum,url"
0  swift                    0x0000000112ef2e78 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x0000000112ef20c5 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x0000000112ef3446 SignalHandler(int) + 262
3  libsystem_platform.dylib 0x00007fff71e175fd _sigtramp + 29
4  libdyld.dylib            0x00007fff71c1d78f dyldGlobalLockRelease() + 0
5  libsystem_c.dylib        0x00007fff71ced808 abort + 120
6  libsystem_c.dylib        0x00007fff71cecac6 err + 0
7  swift                    0x00000001132a97f3 swift::constraints::TupleContextualFailure::TupleContextualFailure(swift::constraints::Solution const&, swift::ContextualTypePurpose, swift::Type, swift::Type, llvm::ArrayRef<unsigned int>, swift::constraints::ConstraintLocator*) (.cold.4) + 35
8  swift                    0x000000010f8ffa67 swift::constraints::TupleContextualFailure::TupleContextualFailure(swift::constraints::Solution const&, swift::ContextualTypePurpose, swift::Type, swift::Type, llvm::ArrayRef<unsigned int>, swift::constraints::ConstraintLocator*) + 359
9  swift                    0x000000010f8f767d swift::constraints::AllowTupleTypeMismatch::coalesceAndDiagnose(swift::constraints::Solution const&, llvm::ArrayRef<swift::constraints::ConstraintFix*>, bool) const + 669
10 swift                    0x000000010f861871 swift::constraints::ConstraintSystem::applySolutionFixes(swift::constraints::Solution const&) + 1889
11 swift                    0x000000010f8620fd swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SolutionApplicationTarget) + 61
12 swift                    0x000000010f9e0919 swift::TypeChecker::typeCheckExpression(swift::constraints::SolutionApplicationTarget&, bool&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 617
13 swift                    0x000000010f9e0617 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 87
14 swift                    0x000000010fa896a4 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 2868
15 swift                    0x000000010fa8a880 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::Stmt>(swift::Stmt*&) + 128
16 swift                    0x000000010fa89072 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 1282
17 swift                    0x000000010fa8a880 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::Stmt>(swift::Stmt*&) + 128
18 swift                    0x000000010fa89642 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 2770
19 swift                    0x000000010fa86a40 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 128
20 swift                    0x000000010fa86b2e swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 158
21 swift                    0x000000010fabb18f swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 239
22 swift                    0x000000010fabc0e5 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 453
23 swift                    0x000000010fabbe14 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 52
24 swift                    0x000000010fabbd86 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::operator()<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 118
25 swift                    0x000000010fabafb0 swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 32
26 swift                    0x000000010edf69d8 swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t, swift::OptionSet<swift::SourceFile::ParsingFlags, unsigned char>) + 680
27 swift                    0x000000010ed19b99 performCompile(swift::CompilerInstance&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 1993
28 swift                    0x000000010ed18420 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3536
29 swift                    0x000000010ecb3ffd main + 861
30 libdyld.dylib            0x00007fff71c1ecc9 start + 1
31 libdyld.dylib            0x0000000000000049 start + 18446603338607629185

Let me take a look

cc @xedin

@LucianoPAlmeida
Copy link
Collaborator

Angelastic (JIRA User) This is fixed on master, can you please verify on the next available master snapshot. Thanks

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants