diff --git a/tools/hangar/__snapshots__/invalid.ts.snap b/tools/hangar/__snapshots__/invalid.ts.snap index 1179a7fc74c..8c2fd4a6dd3 100644 --- a/tools/hangar/__snapshots__/invalid.ts.snap +++ b/tools/hangar/__snapshots__/invalid.ts.snap @@ -1417,69 +1417,76 @@ Duration " `; exports[`explicit_lift_qualification.test.w 1`] = ` -"error: Expected type to be \\"Resource\\", but got \\"str\\" instead - --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:14:10 +"error: Expected type to be \\"IResource\\", but got \\"str\\" instead + --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:22:10 | -14 | lift(prelight_string, [\\"contains\\"]); // Explicit qualification on preflight non-class - | ^^^^^^^^^^^^^^^ Expected type to be \\"Resource\\", but got \\"str\\" instead +22 | lift(prelight_string, [\\"contains\\"]); // Explicit qualification on preflight non-class + | ^^^^^^^^^^^^^^^ Expected type to be \\"IResource\\", but got \\"str\\" instead error: lift() calls must be at the top of the method - --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:10:5 + --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:18:5 | -10 | lift(b, [\\"put\\"]); // Explicit qualification with inflight object, lift call as non first statement +18 | lift(b, [\\"put\\"]); // Explicit qualification with inflight object, lift call as non first statement | ^^^^^^^^^^^^^^^^^ lift() calls must be at the top of the method error: lift() calls must be at the top of the method - --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:14:5 + --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:22:5 | -14 | lift(prelight_string, [\\"contains\\"]); // Explicit qualification on preflight non-class +22 | lift(prelight_string, [\\"contains\\"]); // Explicit qualification on preflight non-class | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lift() calls must be at the top of the method error: lift() calls must be at the top of the method - --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:19:5 + --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:27:5 | -19 | lift(bucket, [inflight_qualifier]); // Explicit qualification with inflight qualifiers, lift call as non first statement +27 | lift(bucket, [inflight_qualifier]); // Explicit qualification with inflight qualifiers, lift call as non first statement | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lift() calls must be at the top of the method error: Expected a preflight object as first argument to \`lift\` builtin, found inflight expression instead - --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:10:10 + --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:18:10 | -10 | lift(b, [\\"put\\"]); // Explicit qualification with inflight object, lift call as non first statement +18 | lift(b, [\\"put\\"]); // Explicit qualification with inflight object, lift call as non first statement | ^ Expected a preflight object as first argument to \`lift\` builtin, found inflight expression instead error: Qualification list must not contain any inflight elements - --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:19:18 + --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:27:18 | -19 | lift(bucket, [inflight_qualifier]); // Explicit qualification with inflight qualifiers, lift call as non first statement +27 | lift(bucket, [inflight_qualifier]); // Explicit qualification with inflight qualifiers, lift call as non first statement | ^^^^^^^^^^^^^^^^^^^^ Qualification list must not contain any inflight elements error: lift() calls are only allowed in inflight methods and closures defined in preflight - --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:24:7 + --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:32:7 | -24 | lift(bucket, [\\"get\\"]); // lift() call in inner closure +32 | lift(bucket, [\\"get\\"]); // lift() call in inner closure | ^^^^^^^^^^^^^^^^^^^^^^ lift() calls are only allowed in inflight methods and closures defined in preflight error: lift() calls are only allowed in inflight methods and closures defined in preflight - --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:29:9 + --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:37:9 | -29 | lift(bucket, [\\"get\\"]); // lift() call in inner class +37 | lift(bucket, [\\"get\\"]); // lift() call in inner class | ^^^^^^^^^^^^^^^^^^^^^^ lift() calls are only allowed in inflight methods and closures defined in preflight error: Expression of type \\"Bucket\\" references an unknown preflight object, can't qualify its capabilities. Use \`lift()\` to explicitly qualify the preflight object to disable this error. - --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:37:5 + --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:45:5 | -37 | b.put(\\"k\\", \\"v\\"); // With no explicit qualification this should be an error +45 | b.put(\\"k\\", \\"v\\"); // With no explicit qualification this should be an error | ^ Expression of type \\"Bucket\\" references an unknown preflight object, can't qualify its capabilities. Use \`lift()\` to explicitly qualify the preflight object to disable this error. +error: Expression of type \\"IPreflightInterface\\" references an unknown preflight object, can't qualify its capabilities. Use \`lift()\` to explicitly qualify the preflight object to disable this error. + --> ../../../examples/tests/invalid/explicit_lift_qualification.test.w:49:5 + | +49 | i.method(); // With no explicit qualification this should be an error + | ^ Expression of type \\"IPreflightInterface\\" references an unknown preflight object, can't qualify its capabilities. Use \`lift()\` to explicitly qualify the preflight object to disable this error. + + Tests 1 failed (1) @@ -2000,10 +2007,10 @@ exports[`impl_interface.test.w 1`] = ` error: Expected type to be \\"inflight (message: str): void\\", but got \\"inflight (x: num): void\\" instead - --> ../../../examples/tests/invalid/impl_interface.test.w:7:7 + --> ../../../examples/tests/invalid/impl_interface.test.w:8:16 | -7 | class B impl cloud.IQueueSetConsumerHandler { - | ^ Expected type to be \\"inflight (message: str): void\\", but got \\"inflight (x: num): void\\" instead +8 | pub inflight handle(x: num) { + | ^^^^^^ Expected type to be \\"inflight (message: str): void\\", but got \\"inflight (x: num): void\\" instead error: Expected an interface, instead found type \\"Bucket\\" @@ -2316,13 +2323,38 @@ Duration " `; exports[`inflight_class_interface_structural_typing.test.w 1`] = ` -"error: Expected type to be \\"IGoo\\", but got \\"NotGoo\\" instead +"error: Inflight class YesGoo cannot implement a preflight interface IGoo + --> ../../../examples/tests/invalid/inflight_class_interface_structural_typing.test.w:15:3 + | +15 | / inflight class YesGoo impl IGoo { +16 | | pub notHandle(): void { +17 | | log(\\"i am goo\\"); +18 | | } +19 | | } + | \\\\---^ Inflight class YesGoo cannot implement a preflight interface IGoo + + +error: Expected type to be \\"IGoo\\", but got \\"NotGoo\\" instead --> ../../../examples/tests/invalid/inflight_class_interface_structural_typing.test.w:26:17 | 26 | let x: IGoo = new NotGoo(); | ^^^^^^^^^^^^ Expected type to be \\"IGoo\\", but got \\"NotGoo\\" instead +error: Expression of type \\"IGoo\\" references an unknown preflight object, can't qualify its capabilities. Use \`lift()\` to explicitly qualify the preflight object to disable this error. + --> ../../../examples/tests/invalid/inflight_class_interface_structural_typing.test.w:23:3 + | +23 | y.notHandle(); + | ^ Expression of type \\"IGoo\\" references an unknown preflight object, can't qualify its capabilities. Use \`lift()\` to explicitly qualify the preflight object to disable this error. + + +error: Expression of type \\"IGoo\\" references an unknown preflight object, can't qualify its capabilities. Use \`lift()\` to explicitly qualify the preflight object to disable this error. + --> ../../../examples/tests/invalid/inflight_class_interface_structural_typing.test.w:27:3 + | +27 | x.notHandle(); + | ^ Expression of type \\"IGoo\\" references an unknown preflight object, can't qualify its capabilities. Use \`lift()\` to explicitly qualify the preflight object to disable this error. + + Tests 1 failed (1) @@ -2435,80 +2467,137 @@ Duration " exports[`interface.test.w 1`] = ` "error: Properties are not supported in interfaces - --> ../../../examples/tests/invalid/interface.test.w:30:3 + --> ../../../examples/tests/invalid/interface.test.w:32:3 | -30 | bar: str; +32 | bar: str; | ^^^^^^^^^ Properties are not supported in interfaces error: Access modifiers are not allowed in interfaces - --> ../../../examples/tests/invalid/interface.test.w:36:3 + --> ../../../examples/tests/invalid/interface.test.w:38:3 | -36 | pub method2(): str; +38 | pub method2(): str; | ^^^^^^^^^^^^^^^^^^^ Access modifiers are not allowed in interfaces error: Expected type annotation - --> ../../../examples/tests/invalid/interface.test.w:42:11 + --> ../../../examples/tests/invalid/interface.test.w:44:11 | -42 | method1(a, b): void; +44 | method1(a, b): void; | ^ Expected type annotation error: Expected type annotation - --> ../../../examples/tests/invalid/interface.test.w:42:14 + --> ../../../examples/tests/invalid/interface.test.w:44:14 | -42 | method1(a, b): void; +44 | method1(a, b): void; | ^ Expected type annotation error: Unknown parser error - --> ../../../examples/tests/invalid/interface.test.w:36:14 + --> ../../../examples/tests/invalid/interface.test.w:38:14 | -36 | pub method2(): str; +38 | pub method2(): str; | ^^ Unknown parser error error: Unknown symbol \\"IB\\" - --> ../../../examples/tests/invalid/interface.test.w:2:22 + --> ../../../examples/tests/invalid/interface.test.w:4:22 | -2 | interface IA extends IB { +4 | interface IA extends IB { | ^^ Unknown symbol \\"IB\\" error: Unknown symbol \\"IDontExist\\" - --> ../../../examples/tests/invalid/interface.test.w:10:26 + --> ../../../examples/tests/invalid/interface.test.w:12:26 | -10 | interface IExist extends IDontExist { +12 | interface IExist extends IDontExist { | ^^^^^^^^^^ Unknown symbol \\"IDontExist\\" error: Unknown symbol \\"ISomeClass\\" - --> ../../../examples/tests/invalid/interface.test.w:16:34 + --> ../../../examples/tests/invalid/interface.test.w:18:34 | -16 | interface ISomeInterface extends ISomeClass { +18 | interface ISomeInterface extends ISomeClass { | ^^^^^^^^^^ Unknown symbol \\"ISomeClass\\" error: Symbol \\"foo\\" already defined in this scope - --> ../../../examples/tests/invalid/interface.test.w:23:5 + --> ../../../examples/tests/invalid/interface.test.w:25:5 | -22 | foo(): void; +24 | foo(): void; | --- previous definition -23 | foo(): void; +25 | foo(): void; | ^^^ Symbol \\"foo\\" already defined in this scope error: Symbol \\"foo\\" already defined in this scope - --> ../../../examples/tests/invalid/interface.test.w:25:5 + --> ../../../examples/tests/invalid/interface.test.w:27:5 | -22 | foo(): void; +24 | foo(): void; | --- previous definition . -25 | foo(): num; +27 | foo(): num; | ^^^ Symbol \\"foo\\" already defined in this scope +error: Inflight class CImplPreflightIface cannot implement a preflight interface IPreflight + --> ../../../examples/tests/invalid/interface.test.w:52:1 + | +52 | / inflight class CImplPreflightIface impl IPreflight { +53 | | pub method1(): void {} +54 | | } + | \\\\-^ Inflight class CImplPreflightIface cannot implement a preflight interface IPreflight + + +error: Expected type to be \\"preflight (): void\\", but got \\"inflight (): void\\" instead + --> ../../../examples/tests/invalid/interface.test.w:53:7 + | +53 | pub method1(): void {} + | ^^^^^^^ Expected type to be \\"preflight (): void\\", but got \\"inflight (): void\\" instead + | + = hint: expected phase to be preflight, but got inflight instead + + +error: Inflight interface IInflightExtendsPreflight cannot extend a preflight interface IPreflight + --> ../../../examples/tests/invalid/interface.test.w:57:20 + | +57 | inflight interface IInflightExtendsPreflight extends IPreflight { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ Inflight interface IInflightExtendsPreflight cannot extend a preflight interface IPreflight + + +error: Inflight interface IInflightExtendsJsii cannot extend a preflight interface ISomeInterface + --> ../../../examples/tests/invalid/interface.test.w:62:20 + | +62 | inflight interface IInflightExtendsJsii extends jsii_fixture.ISomeInterface { + | ^^^^^^^^^^^^^^^^^^^^ Inflight interface IInflightExtendsJsii cannot extend a preflight interface ISomeInterface + + +error: Interface \\"IInflightExtendsJsii\\" extends \\"ISomeInterface\\" but has a conflicting member \\"method\\" (preflight (): void != inflight (): void) + --> ../../../examples/tests/invalid/interface.test.w:62:20 + | +62 | inflight interface IInflightExtendsJsii extends jsii_fixture.ISomeInterface { + | ^^^^^^^^^^^^^^^^^^^^ Interface \\"IInflightExtendsJsii\\" extends \\"ISomeInterface\\" but has a conflicting member \\"method\\" (preflight (): void != inflight (): void) + + +error: Inflight class CInflightImplJsii cannot implement a preflight interface ISomeInterface + --> ../../../examples/tests/invalid/interface.test.w:67:1 + | +67 | / inflight class CInflightImplJsii impl jsii_fixture.ISomeInterface { +68 | | pub method(): void {} +69 | | } + | \\\\-^ Inflight class CInflightImplJsii cannot implement a preflight interface ISomeInterface + + +error: Expected type to be \\"preflight (): void\\", but got \\"inflight (): void\\" instead + --> ../../../examples/tests/invalid/interface.test.w:68:7 + | +68 | pub method(): void {} + | ^^^^^^ Expected type to be \\"preflight (): void\\", but got \\"inflight (): void\\" instead + | + = hint: expected phase to be preflight, but got inflight instead + + Tests 1 failed (1) @@ -3486,9 +3575,9 @@ Duration " exports[`resource_captures.test.w 1`] = ` "error: Expression of type \\"Bucket\\" references an unknown preflight object, can't qualify its capabilities. Use \`lift()\` to explicitly qualify the preflight object to disable this error. - --> ../../../examples/tests/invalid/resource_captures.test.w:15:5 + --> ../../../examples/tests/invalid/resource_captures.test.w:14:5 | -15 | b.put(\\"hello\\", \\"world\\"); +14 | b.put(\\"hello\\", \\"world\\"); | ^ Expression of type \\"Bucket\\" references an unknown preflight object, can't qualify its capabilities. Use \`lift()\` to explicitly qualify the preflight object to disable this error. diff --git a/tools/hangar/__snapshots__/test_corpus/valid/explicit_lift_qualification.test.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/explicit_lift_qualification.test.w_compile_tf-aws.md index 4276905271a..792c230efb5 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/explicit_lift_qualification.test.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/explicit_lift_qualification.test.w_compile_tf-aws.md @@ -63,6 +63,28 @@ module.exports = function({ $inflight_closure }) { //# sourceMappingURL=inflight.$Closure3-1.cjs.map ``` +## inflight.$Closure4-1.cjs +```cjs +"use strict"; +const $helpers = require("@winglang/sdk/lib/helpers"); +module.exports = function({ $bar }) { + class $Closure4 { + constructor({ }) { + const $obj = (...args) => this.handle(...args); + Object.setPrototypeOf($obj, this); + return $obj; + } + async handle() { + ; + const x = $bar; + $helpers.assert($helpers.eq((await x.method()), "ahoy there"), "x.method() == \"ahoy there\""); + } + } + return $Closure4; +} +//# sourceMappingURL=inflight.$Closure4-1.cjs.map +``` + ## inflight.Foo-1.cjs ```cjs "use strict"; @@ -86,6 +108,23 @@ module.exports = function({ $bucket, $put_and_list }) { //# sourceMappingURL=inflight.Foo-1.cjs.map ``` +## inflight.PreflightClass-1.cjs +```cjs +"use strict"; +const $helpers = require("@winglang/sdk/lib/helpers"); +module.exports = function({ }) { + class PreflightClass { + constructor({ }) { + } + async method() { + return "ahoy there"; + } + } + return PreflightClass; +} +//# sourceMappingURL=inflight.PreflightClass-1.cjs.map +``` + ## main.tf.json ```json { @@ -286,6 +325,71 @@ class $Root extends $stdlib.std.Resource { }); } } + class PreflightClass extends $stdlib.std.Resource { + constructor($scope, $id, ) { + super($scope, $id); + } + static _toInflightType() { + return ` + require("${$helpers.normalPath(__dirname)}/inflight.PreflightClass-1.cjs")({ + }) + `; + } + _toInflight() { + return ` + (await (async () => { + const PreflightClassClient = ${PreflightClass._toInflightType()}; + const client = new PreflightClassClient({ + }); + if (client.$inflight_init) { await client.$inflight_init(); } + return client; + })()) + `; + } + get _liftMap() { + return ({ + "method": [ + ], + "$inflight_init": [ + ], + }); + } + } + class $Closure4 extends $stdlib.std.AutoIdResource { + _id = $stdlib.core.closureId(); + constructor($scope, $id, ) { + super($scope, $id); + $helpers.nodeof(this).hidden = true; + } + static _toInflightType() { + return ` + require("${$helpers.normalPath(__dirname)}/inflight.$Closure4-1.cjs")({ + $bar: ${$stdlib.core.liftObject(bar)}, + }) + `; + } + _toInflight() { + return ` + (await (async () => { + const $Closure4Client = ${$Closure4._toInflightType()}; + const client = new $Closure4Client({ + }); + if (client.$inflight_init) { await client.$inflight_init(); } + return client; + })()) + `; + } + get _liftMap() { + return ({ + "handle": [ + [bar, ["method"]], + ], + "$inflight_init": [ + [bar, []], + ], + }); + } + } const bucket = this.node.root.new("@winglang/sdk.cloud.Bucket", cloud.Bucket, this, "Bucket"); (bucket.addObject("k", "value")); const put_and_list = ["put", "list"]; @@ -293,6 +397,8 @@ class $Root extends $stdlib.std.Resource { this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:explicit method lift qualification", new $Closure1(this, "$Closure1")); const inflight_closure = new $Closure2(this, "$Closure2"); this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:explicit closure lift qualification", new $Closure3(this, "$Closure3")); + const bar = new PreflightClass(this, "PreflightClass"); + this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:explicit interface lift qualification", new $Closure4(this, "$Closure4")); } } const $PlatformManager = new $stdlib.platform.PlatformManager({platformPaths: $platforms}); diff --git a/tools/hangar/__snapshots__/test_corpus/valid/explicit_lift_qualification.test.w_test_sim.md b/tools/hangar/__snapshots__/test_corpus/valid/explicit_lift_qualification.test.w_test_sim.md index 1367e42c393..b1ab613e11b 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/explicit_lift_qualification.test.w_test_sim.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/explicit_lift_qualification.test.w_test_sim.md @@ -2,11 +2,12 @@ ## stdout.log ```log -pass ─ explicit_lift_qualification.test.wsim » root/env0/test:explicit method lift qualification -pass ─ explicit_lift_qualification.test.wsim » root/env1/test:explicit closure lift qualification +pass ─ explicit_lift_qualification.test.wsim » root/env0/test:explicit method lift qualification +pass ─ explicit_lift_qualification.test.wsim » root/env1/test:explicit closure lift qualification +pass ─ explicit_lift_qualification.test.wsim » root/env2/test:explicit interface lift qualification -Tests 2 passed (2) +Tests 3 passed (3) Snapshots 1 skipped Test Files 1 passed (1) Duration