Writing a typecheck interop test, confused about result

Hey folks. I'm writing a %target-typecheck-verify-swift test for nodiscard as we don't seem to have any. However, I'm getting some confusing results.

The C++ header is pretty simple:

[[nodiscard]] int NoDiscardAdd(int x, int y);

The test in swift...

NoDiscardAdd(10, 10) // expected-warning {{"result of call to 'NoDiscardAdd' is unused"}}

However this still fails, with the baffling message:

.../swift-project/swift/test/Interop/Cxx/class/nodiscard-typechecker.swift:12:44: error: incorrect message found
NoDiscardAdd(10, 10) // expected-warning {{"result of call to 'NoDiscardAdd' is unused"}}
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                           result of call to 'NoDiscardAdd' is unused

So the expected warning is exactly what I have. If I remove the expected-warning, I get:

.../swift-project/swift/test/Interop/Cxx/class/nodiscard-typechecker.swift:12:1: error: unexpected warning produced: result of call to 'NoDiscardAdd' is unused
NoDiscardAdd(10, 10) 
^

So maybe this is an error, not a warning? What am I missing here?

-Pink

I think the quotation marks might be the problem, could you try to do // expected-warning {{result of call to 'NoDiscardAdd' is unused}} instead?

Bah, that was it. Thank you soooo much. I tinkered with that for a good half hour!

1 Like