     @inlinable func returnTypeName(for record: GIR.Record? = nil, beingIdiomatic: Bool = true) -> String {
         let idiomaticName = idiomaticWrappedTypeName
         let name = beingIdiomatic && !idiomaticName.isEmpty ? idiomaticName : typeRef.fullSwiftTypeName
-        if maybeOptional(for: record) && !name.hasSuffix("?") && !name.hasSuffix("!") {
+        if (typeRef.isOptional || maybeOptional(for: record)) && !name.hasSuffix("?") && !name.hasSuffix("!") {
             return name + "!"
         } else {
             return name

    var swiftParamRef: TypeReference {
        guard var replacement = GIR.swiftParameterTypeReplacements[typeRef] else { return typeRef }
        replacement.isConst = typeRef.isConst
        return replacement
    }


    var swiftReturnRef: TypeReference {
        guard var replacement = GIR.swiftReturnTypeReplacements[typeRef] else { return typeRef }
        replacement.isConst = typeRef.isConst
        replacement.isOptional = typeRef.isOptional
        return replacement
    }

