swift: Error messages for failure to infer generic parameter and opaque result type should be aligned

Description

Consider these two errors:

func f1<T>() -> T { fatalError() }
f1() // error: generic parameter 'T' could not be inferred

func f2() -> Optional<some Sequence> { 
  return nil // error: cannot infer underlying type for opaque result 'Optional<some P>' from return expression
}

Interestingly, the second error is a tailored version of the first, because the underlying type of an opaque result type is in fact a generic parameter of the implicit opaque result type declaration. So these errors are fundamentally one and the same, but the difference in their phrasings is hardly enlightening in this respect. A wording for the second error that is more similar to that of the much more familiar first error would facilitate our efforts in presenting this feature as an extension of the generics system. For example, underlying type for opaque result type '...' could not be inferred from return expression.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 97 (54 by maintainers)

Commits related to this issue

Most upvoted comments

/Users/rajveersingh/swift-project/build/Compiler-Diagnostics/GenericParameterError.swift:9:1: error: generic parameter 'T' could not be inferred
f1() // error: generic parameter 'T' could not be inferred
^
/Users/rajveersingh/swift-project/build/Compiler-Diagnostics/GenericParameterError.swift:8:6: note: in call to function 'f1()'
func f1<T>() -> T { fatalError() }
     ^
/Users/rajveersingh/swift-project/build/Compiler-Diagnostics/GenericParameterError.swift:12:10: error: cannot infer underlying type for opaque result 'Optional<some Sequence>' from return expression
  return nil // error: cannot infer underlying type for opaque result 'Optional<some P>' from return expression
         ^
Program ended with exit code: 1

You may also want to read through our commit message formatting recommendations.

Oh wait, I changed the ARGUMENTS in the info tab to bin/swift-frontend, now it’s working without the Ninja command

Okay, now that we’ve found the message, I trust you can figure out how to modify it and test your changes. Once you’re happy with the new message, don’t forget to update any tests that verify the old message!

Yes, the goal is to find where the error message is defined, so you can edit it. You can either try greping it or use the flag.

The other approach is to use a frontend flag.

To track down where the error is being generated, use git grep (or something similar) to search the code for the error message. That will show you where the message is defined. You can then search for the error message identifier to see where the error is actually being detected.

Keep reading the guide, you might find some valuable resources at the end. Searching for keywords apart from reading, be it in a browser of file system, is often very helpful too.

I mean without the $(ACTION).

Right above troubleshooting build issues

I see, thanks. The part about the architecture is no longer relevant.

If you want to build in Xcode as opposed to the command line, you will have to manually create and configure Xcode targets and hook them up to ninja commands. swift-frontend is the only target you need. The next step explains how to configure the Xcode target.

It is indeed a typo. I changed the default build variant for --xcode the other day and forgot to update the documentation.

Is it this one?

Yep, see? That’s a typo right there.

Yes, only once you’re able to reproduce an issue with a locally built compiler does it make sense to start addressing it. Note that setting up an Xcode workspace is just one option — the IDE/editor choice, as well as whether you use the editor or a terminal to build/run/debug is entirely up to you.