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

Builtin Array Is Exposing Nulls to Surface Language #5494

Closed
wdanilo opened this issue Feb 5, 2023 · 4 comments · Fixed by #5736
Closed

Builtin Array Is Exposing Nulls to Surface Language #5494

wdanilo opened this issue Feb 5, 2023 · 4 comments · Fixed by #5736
Assignees
Labels
--bug Type: bug -compiler p-low Low priority
Milestone

Comments

@wdanilo
Copy link
Member

wdanilo commented Feb 5, 2023

This task is automatically imported from the old Task Issue Board and it was originally created by Radosław Waśko.
Original issue is here.


General Summary

It is possible to encounter pure null values in the surface language if Array elements are accessed when they are not initialized.

Steps to Reproduce

  1. Launch enso repl.
  2. Do the following steps and observe the output:
> a = Array.new 1
>>> Nothing
> b = a.at 0
>>> Nothing
> IO.println b
null
Evaluation failed with: java.lang.NullPointerException
java.lang.Exception: java.lang.NullPointerException
    at org.enso.interpreter.runtime.callable.atom.Atom.lambda$toString$0(Atom.java:80)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    (...)

Expected Result

nulls should not leak to the user. Printing missing values should not result in a crash.

Array API should be designed in such a way to never expose pure nulls to the user.

Actual Result

An exception is thrown.

Enso Version

Enso Launcher
Version:    0.2.0
Built with: scala-2.13.3 for GraalVM 20.2.0
Built from: enso-0.2.0 @ d2df28bc43fcfee614fb31780cd46a59ebb16127
Built on:   Linux (amd64)
Current default Enso engine: 
Enso Compiler and Runtime
Version:    0.2.2-SNAPSHOT
Built with: scala-2.13.3 for GraalVM 20.2.0
Built from: wip/rw/database-library* @ 7e9d7e0ef10a609ead816375386b86f473219bcd
Running on: OpenJDK 64-Bit Server VM, GraalVM Community, JDK 11.0.8+10-jvmci-20.2-b03
            Linux 4.15.0-132-generic (amd64)

Migrated from #1424

@JaroslavTulach
Copy link
Member

With 4dcf802 I am getting the exception even sooner:

enso$ ./built-distribution/enso-engine-0.0.0-dev-linux-amd64/enso-0.0.0-dev/bin/enso --repl
a = Array> a = Array.new 1
>>> Nothing
> b = a.at 0
Evaluation failed with: Null receiver values are not supported by libraries.
java.lang.Exception: Null receiver values are not supported by libraries.
        at com.oracle.truffle.api.library.LibraryFactory.dispatch(LibraryFactory.java:528)
        at com.oracle.truffle.api.library.LibraryFactory.create(LibraryFactory.java:295)
        at org.enso.interpreter.runtime.error.WarningsLibraryGen$CachedDispatch.specialize(WarningsLibraryGen.java:542)
        at org.enso.interpreter.runtime.error.WarningsLibraryGen$CachedDispatch.hasWarnings(WarningsLibraryGen.java:492)
        at org.enso.interpreter.runtime.data.Array.hasWarningElements(Array.java:160)
        at org.enso.interpreter.runtime.data.Array.hasWarnings(Array.java:170)

@JaroslavTulach
Copy link
Member

JaroslavTulach commented Feb 22, 2023

I have a fix:

but there is a question puzzling in my mind: What's the point of having Array.new size now, when there is no set method and Array is immutable!? CCing @jdunkerley and @radeusgd

@JaroslavTulach JaroslavTulach linked a pull request Feb 22, 2023 that will close this issue
2 tasks
@JaroslavTulach JaroslavTulach moved this from 📤 Backlog to 🔧 Implementation in Issues Board Feb 22, 2023
@jdunkerley
Copy link
Member

but there is a question puzzling in my mind: What's the point of having Array.new size now, when there is no set method and Array is immutable!? CCing @jdunkerley and @radeusgd

A fair question - we still have Array in a couple of places, but we should probably reduce this. There are 2 places we use Array.copy to fill it.

@mergify mergify bot closed this as completed in #5736 Feb 22, 2023
@github-project-automation github-project-automation bot moved this from 🔧 Implementation to 🟢 Accepted in Issues Board Feb 22, 2023
@enso-bot
Copy link

enso-bot bot commented Feb 23, 2023

Jaroslav Tulach reports a new STANDUP for yesterday (2023-02-22):

Progress: - Array.allocate: bb03d51

Next Day: Dropdown for Table.join right is wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
--bug Type: bug -compiler p-low Low priority
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants