Array elements not accepted as In-Out parameters

island

(John Perez) #1

The code below works in Swift, but not Silver:

func reverse(first:inout Int,second:inout Int) {
    let tmp=first
    first=second
    second=tmp
}

var nums=[1,2,5,3,6]
reverse(first:&nums[2],second:&nums[4])

The error I get is “E(207) Only fields or local variables can be passed as ‘var’ or ‘out’ for paramter ‘1’”.


UPDATE: IGNORE BELOW, BUG DOES NOT EXIST

The above is when compiling against .NET.

When compiling against Island, type inference doesn’t seem to work and the following needs to be done:

var nums:[Int]=[1,2,5,3,6]

Otherwise, the error: “E(597) Value passed for parameter 1 is nullable but must be not null in call to func MyProgram.reverse(# ref first: Int, # ref second: Int)” is shown.


(marc hoffman) #2

Sounds as designed — a pass-by-reference parameter by definition needs to be a memory location. nums is a collection class with an indexed (subscript in Swift parlance) property — essentially that involves a method call to read and write the value. That cannot possibly be passed “by reference”.

that sounds like a bug, will log. thanx!


(RemObjects) #3

Thanks, logged as bugs://80622


(John Perez) #4

Sounds as designed — a pass-by-reference parameter by definition
needs to be a memory location. nums is a collection class with an
indexed (subscript in Swift parlance) property — essentially that
involves a method call to read and write the value. That cannot
possibly be passed “by reference”.

Right… I tried in repl.it and it works there too though…

I wonder what’s going on under-the-hood


(Carlo Kok) #5

Can you say what you mean with the Island part of this?

I tried this on Island/Windows:

var nums3:[Int]=[1,2,5,3,6]
var nums4=[1,2,5,3,6]
do {
var nums:[Int]=[1,2,5,3,6]
var nums2=[1,2,5,3,6]
	writeLn("hello");
}

(Using Fridays beta) and it seems to work fine.


(John Perez) #6

Sorry, I confused the error message for an earlier build with a successful one. For some reason, VS 2015 doesn’t clear the Error List on a successful build.

There is no bug - type inference works for Arrays


(RemObjects) #7

bugs://80622 got closed with status nochangereq.


(marc hoffman) #8

Hmm. that’s not good. can you give me more details/steps for this?


(John Perez) #9

Ok, this seems to be happening when using the Island Console Application (Windows) solution template (it doesn’t happen with the .NET Console Application template). CTRL-SHIFT-B to build the code below:

func reverse(first:inout Int,second:inout Int) {
    let tmp=first
    first=second
    second=tmp
}

var nums=[1,2,5,3,6]

reverse(first:&nums[2],second:&nums[4])

print()

After it complains about the line with reverse(), comment out that line and do a CTRL-SHIFT-B, the build will complete successfully but the Error List is not cleared. This is under Visual Studio 2015 Community Edition Update 3.


(RemObjects) #10

Thanks, logged as bugs://80649


(John Perez) #11

I’ve noticed the problem with the build Error List not being cleared just now with a Winforms project template as well: SilverWinforms3.zip (220.7 KB)

Try to build this project and you will get an error:

Error (E46) Unknown identifier “SilverWinforms3.Properties”_

in the Error List. Fix this by going to Main.Designer.swift and remove line 27 (self.pictureBox1.Image = ...) and you will build successfully, but the items in the Error List remain.

This is under Visual Studio 2015 Community Edition, Elements 10.0.0.2311


(RemObjects) #12

bugs://80649 got closed with status fixed.


(John Perez) #13

Hi,

Can you post the latest version “RemObjects Elements with Water - 10.0.0.2319” to my personal downloads “jbperez808” so I can do more testing and bug reports? Getting back to testing out Silver after a few weeks hiatus.


(marc hoffman) #14

Done! In all likelihood, .2319 will also become public/stable, next week.