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

Bad field gives ArrayIndexOutOfBoundsException #8

Open
julianhyde opened this issue Dec 3, 2019 · 0 comments
Open

Bad field gives ArrayIndexOutOfBoundsException #8

julianhyde opened this issue Dec 3, 2019 · 0 comments

Comments

@julianhyde
Copy link
Collaborator

julianhyde commented Dec 3, 2019

Bad field gives ArrayIndexOutOfBoundsException. For example,

let val e1 = {name="Fred",empno=10} in #ename e1 end;
java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 2
	at java.base/java.util.Arrays$ArrayList.get(Arrays.java:4351)
	at net.hydromatic.morel.eval.Codes.lambda$nth$23(Codes.java:335)
	at net.hydromatic.morel.eval.Codes.lambda$apply$20(Codes.java:206)
	at net.hydromatic.morel.eval.Codes.lambda$let$17(Codes.java:177)
	at net.hydromatic.morel.compile.Compiler.lambda$compileValBind$8(Compiler.java:512)
	at net.hydromatic.morel.compile.Compiler$1.eval(Compiler.java:76)
	at net.hydromatic.morel.Shell.run(Shell.java:250)
	at net.hydromatic.morel.Shell.main(Shell.java:75)

It should give a better error message.

Here's what sml does in a similar situation:

- let val e1 = {name="Fred",empno=10} in #name e1 end;
val it = "Fred" : string
- let val e1 = {name="Fred",empno=10} in #ename e1 end;
stdIn:2.40-2.49 Error: operator and operand don't agree [record labels]
  operator domain: {ename:'Y; 'Z}
  operand:         {empno:[int ty], name:string}
  in expression:
    (fn {ename=ename,...} => ename) e1

The problem also occurs in from expressions:

from e in [{empno=10, name="Fred"}] yield {no = #empno e, name = #ename e};
java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 2
	at java.base/java.util.Arrays$ArrayList.get(Arrays.java:4351)
	at net.hydromatic.morel.eval.Codes.lambda$nth$23(Codes.java:335)
	at net.hydromatic.morel.eval.Codes.lambda$apply$20(Codes.java:206)
	at net.hydromatic.morel.eval.Codes$TupleCode.eval(Codes.java:891)
	at net.hydromatic.morel.eval.Codes$2.loop(Codes.java:246)
	at net.hydromatic.morel.eval.Codes$2.loop(Codes.java:253)
	at net.hydromatic.morel.eval.Codes$2.eval(Codes.java:236)
	at net.hydromatic.morel.compile.Compiler.lambda$compileValBind$8(Compiler.java:512)
	at net.hydromatic.morel.compile.Compiler$1.eval(Compiler.java:76)
	at net.hydromatic.morel.Shell.run(Shell.java:250)
	at net.hydromatic.morel.Shell.main(Shell.java:75)
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

No branches or pull requests

1 participant