How to use index RTL type

Hello,

I want to use the range index, and let the following codes complie fine when targeting JAVA:

var array = new int[] { 1, 2, 3, 4, 5 };
var lastItem = array[^1];

It’s fine for .net. But on JAVA, I got the error:

“From End” operator requires an Index rtl type.

How can I use the ^, and … sytax when targeting JAVA?

Thanks.

Regards,
Xiaoguang

I believe this feature is specific to .NET, as it relies on runtime support by the class library. But I’ll log an issue to investigate iof we can provide support for it for the opther platforms, as well…

Logged as bugs://E26075.

Done (and works) for Java and Toffee

1 Like

Excellent! Very glad to hear that.

1 Like

I’ve put a new build into your Personal Downloads. Let me know how it goes! :crossed_fingers:t3:

Hello, the following codes are now complie fine on both .net and JAVA

var array = new int[] { 1, 2, 3, 4, 5 };
var lastItem = array[^1];

But the following codes are not complie fine on either .net or JAVA.

var testStr = “abcdefg”;
var str1 = testStr[…1];
var str2 = testStr[1…];
var str3 = testStr[^1…];
var str4 = testStr[…^1];
var str5 = testStr[1…6];

on .net:


// The chinese words means “object reference is not set to object instance”

on JAVA:

Behaviour in visual C#:

Yeah,

that’s the only code I tested.

Hmm. That sounds like a compiler bug. reproduced; will log.

This might be as designed, if java.String does not provide an indexer property that accepts a Range?

Logged as bugs://E26076.

Unfortunately this one will have to wait until next week, probalby.

I am not quite familiar with JAVA, so I am not sure. Just recently want to know something about the JAVA tech stack such as Gradle, and cross platform development. But the more I study, the more I like .Net:)

But var str1 = testStr[…1]; should work on .Net since it’s C# 8 sytax.

“Unfortunately this one will have to wait until next week, probalby”, no problem, it’s not urgent for me.

Another issue I found on this forum is:

When paste the codes, looks like 2 full stop will become 3 full stop, such as var str1 = testStr[…1]

Yes, this one is a compiler bug. Any “Internal Error” is.

Ok, cool.

yeah, I noticed that too. it seems any set of two or more dots gets turned into a single ellipsis character. Strange. That’s why its always good to close code snippets in back ticks (for a single line) or start./end code blocks with three backticks

var str1 = testStr[........1];
var str1 = testStr[…1];

code
code code

image

bugs://E26075 was closed as fixed.

@mh Hi, any update on bug E26076?

Still open, i’m afraid, along with another Index-related bug I logged myself. I’ll try to get this priority next week. :crossed_fingers:t3:

OK, thanks, that’s great!

1 Like

Do you actually still see this IE? i now get a new error (logged as separate issue) with your testcase:

			var str1 = testStr[..1]; // E486 Parameter 1 is "<error>", should be "Int32", in call to Char String.get Chars(Int32 index)
			var str2 = testStr[1..]; // E486 Parameter 1 is "<error>", should be "Int32", in call to Char String.get Chars(Int32 index)
			var str3 = testStr[^1..]; // E486 Parameter 1 is "<error>", should be "Int32", in call to Char String.get Chars(Int32 index)
			var str4 = testStr[..^1]; // E486 Parameter 1 is "<error>", should be "Int32", in call to Char String.get Chars(Int32 index)
			var str5 = testStr[1..6]; // E486 Parameter 1 is "Range", should be "Int32", in call to Char String.get Chars(Int32 index)

this one is being tracked as bugs://E26124: C# Range operator doesn’t work as advertised, and seems to be a combination of two slightly unrelated bugs:

(a) the .. C# language syntax just doesn’t seem to be handled correctly, for open-ended ranges
(b).NET doesn’t have explicit overlords that take a Range, but expects the compiler to map those under the hood back to normal index-based calls. this isn’t happening (properly).

Hi,

On my computer with Element 2773:

I think C# language treats like this:

…1 // From the begining but dont’t take the index 1 element, so just take the index 0 element
1… // Take the index 1 element and the rest
^1… // This one is specail. The counting is from 1. ^1 mean the last element, and because no element after it, so only output the last element.
…^1 // output all except the last element
1…6 // output the 1 to 5 elements

But what does the magic the complier did, I have no idea.

Good. that matches what I have.