Problem 654 (Maximum Binary Tree)): "error: 'serialize' produces 'String', not the expected ..."

I am hitting a compile-time error in Swift that I believe is not due to my fault (it is not in my code). The error is:

Line 34, Char 42: error: 'serialize' produces 'String', not the expected contextual result type 'String' in solution.swift
        let out: String = __Serializer__.serialize(ret)
                                         ^

My code is (minimized for as trivial repro as possible):

public class TreeNode {
    public var val: Int
    public var left: TreeNode?
    public var right: TreeNode?
    public init(_ val: Int) {
        self.val = val
        self.left = nil
        self.right = nil
    }
}

class Solution {
    func constructMaximumBinaryTree(_ nums: [Int]) -> TreeNode? {
        return TreeNode(0)
    }
}

The same code compiles cleanly in a playground.

Comments (1)