dplassgit / d2lang

D2 is a strongly-typed, statically-typed, (mostly) inferred-type compiled language.
MIT License
6 stars 1 forks source link

Runtime exception for index out of range #260

Closed dplassgit closed 1 year ago

dplassgit commented 1 year ago

Source:

a="hello"
println a[5]

Produces this error:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 5
        at java.lang.String.charAt(String.java:658)
        at com.plasstech.lang.d2.optimize.ArithmeticOptimizer.visit(ArithmeticOptimizer.java:273)
        at com.plasstech.lang.d2.codegen.il.BinOp.accept(BinOp.java:47)
        at com.plasstech.lang.d2.optimize.LineOptimizer.optimize(LineOptimizer.java:56)
        at com.plasstech.lang.d2.optimize.ILOptimizer.optimize(ILOptimizer.java:77)
        at com.plasstech.lang.d2.optimize.ILOptimizer.execute(ILOptimizer.java:58)
        at com.plasstech.lang.d2.D2Compiler.main(D2Compiler.java:77)