-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compiler): error when type (class) defined before
super()
call (#…
…6535) This is part of the effort to address #4925. Because inflight closures turn into class definitions, when they are passed to a `super()` call we use to get an error telling us that `super()` must be the first statement in a ctor. Now this is fixed: ```wing class Foo { new(x: num) {} } class Bar extends Foo { new() { class Baz {} // This is now ok super(1); } } ``` This PR also improves the diagnostics for mssing super calls or "not first statement" super calls. note: waiting for #6531 to be merged first. ## Checklist - [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [x] Description explains motivation and solution - [x] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
- Loading branch information
1 parent
db0720d
commit 4b42f9d
Showing
7 changed files
with
240 additions
and
45 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
172 changes: 172 additions & 0 deletions
172
libs/wingc/src/jsify/snapshots/allow_type_def_before_super.snap
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,172 @@ | ||
--- | ||
source: libs/wingc/src/jsify/tests.rs | ||
--- | ||
## Code | ||
|
||
```w | ||
class Foo { | ||
new(x: num) {} | ||
} | ||
class Bar extends Foo { | ||
new() { | ||
class Baz {} | ||
super(1); | ||
} | ||
} | ||
``` | ||
|
||
## inflight.Bar-1.cjs | ||
|
||
```js | ||
"use strict"; | ||
const $helpers = require("@winglang/sdk/lib/helpers"); | ||
module.exports = function({ $Foo }) { | ||
class Bar extends $Foo { | ||
constructor({ }) { | ||
super({ }); | ||
} | ||
} | ||
return Bar; | ||
} | ||
//# sourceMappingURL=inflight.Bar-1.cjs.map | ||
``` | ||
|
||
## inflight.Baz-1.cjs | ||
|
||
```js | ||
"use strict"; | ||
const $helpers = require("@winglang/sdk/lib/helpers"); | ||
module.exports = function({ }) { | ||
class Baz { | ||
constructor({ }) { | ||
} | ||
} | ||
return Baz; | ||
} | ||
//# sourceMappingURL=inflight.Baz-1.cjs.map | ||
``` | ||
|
||
## inflight.Foo-1.cjs | ||
|
||
```js | ||
"use strict"; | ||
const $helpers = require("@winglang/sdk/lib/helpers"); | ||
module.exports = function({ }) { | ||
class Foo { | ||
constructor({ }) { | ||
} | ||
} | ||
return Foo; | ||
} | ||
//# sourceMappingURL=inflight.Foo-1.cjs.map | ||
``` | ||
|
||
## preflight.cjs | ||
|
||
```js | ||
"use strict"; | ||
const $stdlib = require('@winglang/sdk'); | ||
const $platforms = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLATFORMS); | ||
const $outdir = process.env.WING_SYNTH_DIR ?? "."; | ||
const $wing_is_test = process.env.WING_IS_TEST === "true"; | ||
const std = $stdlib.std; | ||
const $helpers = $stdlib.helpers; | ||
const $extern = $helpers.createExternRequire(__dirname); | ||
class $Root extends $stdlib.std.Resource { | ||
constructor($scope, $id) { | ||
super($scope, $id); | ||
class Foo extends $stdlib.std.Resource { | ||
constructor($scope, $id, x) { | ||
super($scope, $id); | ||
} | ||
static _toInflightType() { | ||
return ` | ||
require("${$helpers.normalPath(__dirname)}/inflight.Foo-1.cjs")({ | ||
}) | ||
`; | ||
} | ||
_toInflight() { | ||
return ` | ||
(await (async () => { | ||
const FooClient = ${Foo._toInflightType()}; | ||
const client = new FooClient({ | ||
}); | ||
if (client.$inflight_init) { await client.$inflight_init(); } | ||
return client; | ||
})()) | ||
`; | ||
} | ||
get _liftMap() { | ||
return ({ | ||
"$inflight_init": [ | ||
], | ||
}); | ||
} | ||
} | ||
class Bar extends Foo { | ||
constructor($scope, $id, ) { | ||
class Baz extends $stdlib.std.Resource { | ||
constructor($scope, $id, ) { | ||
super($scope, $id); | ||
} | ||
static _toInflightType() { | ||
return ` | ||
require("${$helpers.normalPath(__dirname)}/inflight.Baz-1.cjs")({ | ||
}) | ||
`; | ||
} | ||
_toInflight() { | ||
return ` | ||
(await (async () => { | ||
const BazClient = ${Baz._toInflightType()}; | ||
const client = new BazClient({ | ||
}); | ||
if (client.$inflight_init) { await client.$inflight_init(); } | ||
return client; | ||
})()) | ||
`; | ||
} | ||
get _liftMap() { | ||
return ({ | ||
"$inflight_init": [ | ||
], | ||
}); | ||
} | ||
} | ||
super($scope, $id, 1); | ||
} | ||
static _toInflightType() { | ||
return ` | ||
require("${$helpers.normalPath(__dirname)}/inflight.Bar-1.cjs")({ | ||
$Foo: ${$stdlib.core.liftObject(Foo)}, | ||
}) | ||
`; | ||
} | ||
_toInflight() { | ||
return ` | ||
(await (async () => { | ||
const BarClient = ${Bar._toInflightType()}; | ||
const client = new BarClient({ | ||
}); | ||
if (client.$inflight_init) { await client.$inflight_init(); } | ||
return client; | ||
})()) | ||
`; | ||
} | ||
get _liftMap() { | ||
return $stdlib.core.mergeLiftDeps(super._liftMap, { | ||
"$inflight_init": [ | ||
], | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
const $PlatformManager = new $stdlib.platform.PlatformManager({platformPaths: $platforms}); | ||
const $APP = $PlatformManager.createApp({ outdir: $outdir, name: "main", rootConstruct: $Root, isTestEnvironment: $wing_is_test, entrypointDir: process.env['WING_SOURCE_DIR'], rootId: process.env['WING_ROOT_ID'] }); | ||
$APP.synth(); | ||
//# sourceMappingURL=preflight.cjs.map | ||
``` | ||
|
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