Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change assert to allow blank strings #1177

Merged
merged 5 commits into from
Mar 31, 2020

Conversation

DuncanUszkay1
Copy link
Contributor

@DuncanUszkay1 DuncanUszkay1 commented Mar 16, 2020

Issue: #1176

When using the documented --use abort=abort would be set to an empty string, which resulted in the call to global aliases returning ''. Then since blank strings are falsey, this assertion would fail.

I've changed the assertion to assert that the name is a string, which catches the case that the alias is missing but does not fail in the case of an empty string

examples:
If the name isn't found in the aliases table:

//let alias = unchecked(_keys[i]);
let alias = "not the right key"
let name = globalAliases.get(alias);
assert(isString(name));

We get: ERROR: AssertionError: assertion failed as expected.

In the case where you specify an abort that does not match any export:
ERROR: no such global element: main/nope as before

In the case where you use a blank abort, compilation is successful.

@DuncanUszkay1 DuncanUszkay1 changed the title Change assert to a ! to allow for "" Change assert to allow blank strings Mar 16, 2020
src/program.ts Outdated
@@ -1044,7 +1044,9 @@ export class Program extends DiagnosticEmitter {
// TODO: for (let [alias, name] of globalAliases) {
for (let _keys = Map_keys(globalAliases), i = 0, k = _keys.length; i < k; ++i) {
let alias = unchecked(_keys[i]);
let name = assert(globalAliases.get(alias));
let name = globalAliases.get(alias);
Copy link
Member

@dcodeIO dcodeIO Mar 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just use changetype<string>(globalAliases.get(alias)) since the value can't be null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it can be undefined right?

alias = "bad key"
let name = changetype<string>(globalAliases.get(alias))
if (!name.length) continue; // explicitly disabled

throws

ERROR: TypeError: Cannot read property 'length' of undefined

I suppose that's not really much different than the assertion though and shouldn't really happen anyway

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yeah, that's strange. Might be cli/asc.js wrongly inserting an undefined into the map.

Copy link
Member

@dcodeIO dcodeIO Mar 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, alias = "bad key" doesn't happen since we _keys = Map_keys(globalAliases) so we know the key is in there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay- well in that case maybe we should just use ! and ignore the undefined case

src/program.ts Outdated Show resolved Hide resolved
@DuncanUszkay1 DuncanUszkay1 marked this pull request as ready for review March 20, 2020 00:19
@DuncanUszkay1
Copy link
Contributor Author

Not sure I understand why CI is failing here- doesn't appear to be related to the PR

@dcodeIO
Copy link
Member

dcodeIO commented Mar 20, 2020

Seems to me that there's something wrong with GitHub's git, hmm. Will try to rerun the CI job at a later time.

@DuncanUszkay1
Copy link
Contributor Author

Is this blocked on CI failures?

@DuncanUszkay1
Copy link
Contributor Author

CI is passing now, should be good to merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants