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

run breaks type safety #2068

Open
byorgey opened this issue Jul 21, 2024 · 3 comments
Open

run breaks type safety #2068

byorgey opened this issue Jul 21, 2024 · 3 comments
Labels
Bug The observed behaviour is incorrect or unexpected. L-Type system Issues related to the Swarm language type system.

Comments

@byorgey
Copy link
Member

byorgey commented Jul 21, 2024

Describe the bug
Executing run can overwrite existing definitions with new definitions having different types. This can break type safety if the overwritten names were used in the same expression.

To Reproduce
Create a file m.sw:

echo "def m = move end" > m.sw

Now, in a Creative mode game:

> def m = 4 end; run "m.sw"; return (m + 1)

Results in a Fatal error: bad application of execConst...

Expected behavior
I don't even know what is expected. This is just yet more evidence that run is broken; see #495 . This would not be a problem with a proper import command since the second m would be typechecked with the type it has in m.sw, as it should.

Additional context
I thought of this when reading @xsebek's clever hacks in #2064 😄

@byorgey byorgey added Bug The observed behaviour is incorrect or unexpected. L-Type system Issues related to the Swarm language type system. labels Jul 21, 2024
@xsebek
Copy link
Member

xsebek commented Jul 22, 2024

Well, run should probably not let its definitions escape, but then it would not be as useful.

I am surprised that this bug allows me to use m. It does feel a bit like calling external functions from C - if you mess up the signature, you get a runtime error.

@byorgey
Copy link
Member Author

byorgey commented Jul 22, 2024

Well, run should probably not let its definitions escape

That is the entire point of run 😆

@xsebek
Copy link
Member

xsebek commented Jul 22, 2024

The name does sound like it just runs a script with commands - it even has type Cmd Unit.

If import was limited to importing definitions, I would be OK with run just running scripts and not overwriting outer scope definitions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The observed behaviour is incorrect or unexpected. L-Type system Issues related to the Swarm language type system.
Projects
None yet
Development

No branches or pull requests

2 participants