-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement Swift errors 🥳 (#430)
* chore: Use C++ 23 * feat: Add `ResultWrappingType` * feat: Add C++ `ResultWrappingType` bridge * feat: Use C++ result wrapper * feat: Use `std::expected` for Swift return types * Bump to 23 * Downgrade to C++ 20 again * fix: Use `Result<T>` instead of expected * fix: Return even if void * fix: Explicitly say type * extra line for debugging * fix: Fix double args * fix: Bridge directly to C++ target for return values * feat: THROW SWIFT ERROR WOOHOOO * feat: Make it work * feat: Add test that uses `Result<complex type>` and throws before * Update getTests.ts * Update HybridTestObjectKotlin.kt * extra line * perf: Use `assert` for `value()` * docs: Remove error swift limitation as it now works
- Loading branch information
Showing
32 changed files
with
1,237 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { Language } from '../../getPlatformSpecs.js' | ||
import { type SourceFile, type SourceImport } from '../SourceFile.js' | ||
import { ErrorType } from './ErrorType.js' | ||
import type { Type, TypeKind } from './Type.js' | ||
|
||
export class ResultWrappingType implements Type { | ||
readonly result: Type | ||
readonly error: Type | ||
|
||
constructor(result: Type) { | ||
this.result = result | ||
this.error = new ErrorType() | ||
} | ||
|
||
get canBePassedByReference(): boolean { | ||
return this.result.canBePassedByReference | ||
} | ||
|
||
get kind(): TypeKind { | ||
return 'result-wrapper' | ||
} | ||
|
||
getCode(language: Language): string { | ||
switch (language) { | ||
case 'c++': | ||
return `Result<${this.result.getCode(language)}>` | ||
case 'swift': | ||
return this.result.getCode(language) | ||
default: | ||
throw new Error( | ||
`Language ${language} is not yet supported for VariantType!` | ||
) | ||
} | ||
} | ||
getExtraFiles(): SourceFile[] { | ||
return [...this.result.getExtraFiles(), ...this.error.getExtraFiles()] | ||
} | ||
getRequiredImports(): SourceImport[] { | ||
return [ | ||
{ | ||
language: 'c++', | ||
name: 'NitroModules/Result.hpp', | ||
space: 'system', | ||
}, | ||
...this.result.getRequiredImports(), | ||
...this.error.getRequiredImports(), | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ export type TypeKind = | |
| 'struct' | ||
| 'tuple' | ||
| 'variant' | ||
| 'result-wrapper' | ||
| 'void' | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.