Skip to content

Compiler error does not help me figure out the problem with this code: #155

Answered by mbrandonw
andreweades asked this question in Q&A
Discussion options

You must be logged in to vote

There's a few things going on here that are causing bad error messaging. First of all, Double's initializer is not failable so you can drop the force unwrap:

 let stackElement = Parse {
   StackElement.number($0)
 } with: {
-  Int.parser().map { Double($0)! }
+  Int.parser().map { Double($0) }
 }

Now the error message is "Ambiguous use of 'init(_:)'". This is happening because Int.parser() is overloaded quite a bit in order to support parsing on multiple string representations such as Substring and UTF8View, and in the current situation it can't figure out the type of input. You can explicitly specify the input to fix it:

 let stackElement = Parse {
   StackElement.number($0)
 } with: {
-

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by andreweades
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #154 on February 27, 2022 17:13.