Bug 165477
| Summary: | Functions with a return type of ExceptionOr<String> cannot "return emptyString();" | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Jer Noble <jer.noble> |
| Component: | Tools / Tests | Assignee: | Nobody <webkit-unassigned> |
| Status: | NEW | ||
| Severity: | Normal | CC: | darin, lforschler, sam |
| Priority: | P2 | ||
| Version: | WebKit Nightly Build | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
Jer Noble
Attempting to do so generates the following error:
error: no viable conversion from returned value of type 'const WTF::String' to function return type 'ExceptionOr<WTF::String>'
With the following notes:
ExceptionOr.h:35:37: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const WTF::String' to 'const WebCore::ExceptionOr<WTF::String> &' for 1st argument
ExceptionOr.h:37:5: note: candidate constructor not viable: no known conversion from 'const WTF::String' to 'WebCore::Exception &&' for 1st argument
ExceptionOr.h:38:5: note: candidate constructor not viable: 1st argument ('const WTF::String') would lose const qualifier
ExceptionOr.h:39:88: note: candidate template ignored: disabled by 'enable_if' [with OtherType = WTF::String]
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Darin Adler
The workaround is to write this:
return String { emptyString() };
I’m not sure we need to fix this.
Darin Adler
Let me know if the workaround works or not.
I’m sure we can come up with a way to make the syntax more elegant if this comes up a lot.
Darin Adler
I think this came up for me one time: in Internals::captionsStyleSheetOverride.
Jer Noble
(In reply to comment #2)
> Let me know if the workaround works or not.
It does!
> I’m sure we can come up with a way to make the syntax more elegant if this
> comes up a lot.
I understand the motivation for not allowing "initialization-by-copy-constructor" by default, but I think this pattern may become more common. Enum values in WebIDL are turn into Strings in the bindings, and I've often defined "static const String& enumValue();" methods in tho bound classes to represent each enumerated value. A getter that can either return an enum value or throw an exception will likely hit this quirk. It may be worth it to make an exception (hah!) for ExceptionOr<String> or ExceptionOr<AtomicString>.