Csound Csound-dev Csound-tekno Search About

[Csnd-dev] instr0 non-globals affecting variable assignment in instruments

Date2025-12-07 23:54
FromRichard Knight
Subject[Csnd-dev] instr0 non-globals affecting variable assignment in instruments
I'm moving to Csound 7 and some of my collection of UDOs don't work - 
there are some patterns such as the one below in some files, which 
caused compilation to fail with the following error:

error: Array variable name 'Sresult' used before as a different type at 
line 14
SEMERR: Array variable name 'Sresult' used before as a different type at 
line 14

I can see why this is happening (conflicting types of Sresult) and how 
to work around, but is this expected behaviour?
Notably this seems to only occur only in opcodes and if arrays are 
involved - if I move the contents of the opcode into an instr then it 
works OK, and numeric/string primitives work OK in this pattern.


Sresult = "anything"

opcode test1, S[], 0
         Sresult[] fillarray "t1", "t2"
         xout Sresult
endop

instr 1
         Sresult[] test1
endin

Date2025-12-08 06:51
FromHlöðver Sigurðsson
SubjectRe: [Csnd-dev] instr0 non-globals affecting variable assignment in instruments
It would sound complicated to me to maintain a behaviour where one variable name maps to two different slots of memory. I feel the way globalVarPool and instrVarPool in csound7 is designed nicely but perhaps how it was designed in csound6 it allowed this edge case to go unnoticed. I leave to the voice of the people of csound what we want to happen here. But my view would be that redeclaring a variable name of different type should be an error. It's not only difficult to maintain ambiguity in memory but it also makes the code difficult to read and understand.

On Mon, 8 Dec 2025 at 01:54, Richard Knight <richard@1bpm.net> wrote:
I'm moving to Csound 7 and some of my collection of UDOs don't work -
there are some patterns such as the one below in some files, which
caused compilation to fail with the following error:

error: Array variable name 'Sresult' used before as a different type at
line 14
SEMERR: Array variable name 'Sresult' used before as a different type at
line 14

I can see why this is happening (conflicting types of Sresult) and how
to work around, but is this expected behaviour?
Notably this seems to only occur only in opcodes and if arrays are
involved - if I move the contents of the opcode into an instr then it
works OK, and numeric/string primitives work OK in this pattern.


Sresult = "anything"

opcode test1, S[], 0
         Sresult[] fillarray "t1", "t2"
         xout Sresult
endop

instr 1
         Sresult[] test1
endin

Date2025-12-08 08:22
Fromvlz
SubjectRe: [Csnd-dev] instr0 non-globals affecting variable assignment in instruments
The code should work, could you open an issue and we'll take a look. The other issue should be fixed once we merge the PR.

best
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 7 Dec 2025, at 23:54, Richard Knight  wrote:
> 
> I'm moving to Csound 7 and some of my collection of UDOs don't work - there are some patterns such as the one below in some files, which caused compilation to fail with the following error:
> 
> error: Array variable name 'Sresult' used before as a different type at line 14
> SEMERR: Array variable name 'Sresult' used before as a different type at line 14
> 
> I can see why this is happening (conflicting types of Sresult) and how to work around, but is this expected behaviour?
> Notably this seems to only occur only in opcodes and if arrays are involved - if I move the contents of the opcode into an instr then it works OK, and numeric/string primitives work OK in this pattern.
> 
> 
> Sresult = "anything"
> 
> opcode test1, S[], 0
>        Sresult[] fillarray "t1", "t2"
>        xout Sresult
> endop
> 
> instr 1
>        Sresult[] test1
> endin

Date2025-12-08 10:03
FromVictor Lazzarini <000010b17ddd988e-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd-dev] [EXTERNAL] [Csnd-dev] instr0 non-globals affecting variable assignment in instruments
Hi Richard,

I found the bug and sent in a PR

https://github.com/csound/csound/pull/2380

fixing this. Thanks for reporting it.
========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 7 Dec 2025, at 23:54, Richard Knight  wrote:
> 
> *Warning*
> 
> This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
> 
> I'm moving to Csound 7 and some of my collection of UDOs don't work -
> there are some patterns such as the one below in some files, which
> caused compilation to fail with the following error:
> 
> error: Array variable name 'Sresult' used before as a different type at
> line 14
> SEMERR: Array variable name 'Sresult' used before as a different type at
> line 14
> 
> I can see why this is happening (conflicting types of Sresult) and how
> to work around, but is this expected behaviour?
> Notably this seems to only occur only in opcodes and if arrays are
> involved - if I move the contents of the opcode into an instr then it
> works OK, and numeric/string primitives work OK in this pattern.
> 
> 
> Sresult = "anything"
> 
> opcode test1, S[], 0
>        Sresult[] fillarray "t1", "t2"
>        xout Sresult
> endop
> 
> instr 1
>        Sresult[] test1
> endin

Date2025-12-08 11:33
FromRichard Knight
SubjectRe: [Csnd-dev] [EXTERNAL] [Csnd-dev] instr0 non-globals affecting variable assignment in instruments
Hi,

Appreciate you both looking into this and the other issue so quickly.
I'm moving a quite large codebase and plugins to Csound 7 and have a 
performance on Thursday so hoping to take it out in public then :)

Thank you all for your efforts and work, I'm excited to finally get 
round to using CS7 in earnest.
RK

On 2025-12-08 10:03, Victor Lazzarini wrote:
> Hi Richard,
> 
> I found the bug and sent in a PR
> 
> https://github.com/csound/csound/pull/2380
> 
> fixing this. Thanks for reporting it.
> ========================
> Prof. Victor Lazzarini
> Maynooth University
> Ireland
> 
>> On 7 Dec 2025, at 23:54, Richard Knight  wrote:
>> 
>> *Warning*
>> 
>> This email originated from outside of Maynooth University's Mail 
>> System. Do not reply, click links or open attachments unless you 
>> recognise the sender and know the content is safe.
>> 
>> I'm moving to Csound 7 and some of my collection of UDOs don't work -
>> there are some patterns such as the one below in some files, which
>> caused compilation to fail with the following error:
>> 
>> error: Array variable name 'Sresult' used before as a different type 
>> at
>> line 14
>> SEMERR: Array variable name 'Sresult' used before as a different type 
>> at
>> line 14
>> 
>> I can see why this is happening (conflicting types of Sresult) and how
>> to work around, but is this expected behaviour?
>> Notably this seems to only occur only in opcodes and if arrays are
>> involved - if I move the contents of the opcode into an instr then it
>> works OK, and numeric/string primitives work OK in this pattern.
>> 
>> 
>> Sresult = "anything"
>> 
>> opcode test1, S[], 0
>>        Sresult[] fillarray "t1", "t2"
>>        xout Sresult
>> endop
>> 
>> instr 1
>>        Sresult[] test1
>> endin

Date2025-12-08 12:07
FromVictor Lazzarini <000010b17ddd988e-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd-dev] [EXTERNAL] [Csnd-dev] instr0 non-globals affecting variable assignment in instruments
It’s not a problem, we’re thankful to have it spotted. It was actually such a basic bug that I was
surprised it had not been caught before but I guess we did not have a test for it, now we do.

The other bugfix should be merged soon, just waiting on the review.
========================
Prof. Victor Lazzarini
Maynooth University
Ireland


> On 8 Dec 2025, at 11:33, Richard Knight  wrote:
>
> Hi,
>
> Appreciate you both looking into this and the other issue so quickly.
> I'm moving a quite large codebase and plugins to Csound 7 and have a performance on Thursday so hoping to take it out in public then :)
>
> Thank you all for your efforts and work, I'm excited to finally get round to using CS7 in earnest.
> RK
>
> On 2025-12-08 10:03, Victor Lazzarini wrote:
>> Hi Richard,
>> I found the bug and sent in a PR
>> https://github.com/csound/csound/pull/2380
>> fixing this. Thanks for reporting it.
>> ========================
>> Prof. Victor Lazzarini
>> Maynooth University
>> Ireland
>>> On 7 Dec 2025, at 23:54, Richard Knight  wrote:
>>> *Warning*
>>> This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
>>> I'm moving to Csound 7 and some of my collection of UDOs don't work -
>>> there are some patterns such as the one below in some files, which
>>> caused compilation to fail with the following error:
>>> error: Array variable name 'Sresult' used before as a different type at
>>> line 14
>>> SEMERR: Array variable name 'Sresult' used before as a different type at
>>> line 14
>>> I can see why this is happening (conflicting types of Sresult) and how
>>> to work around, but is this expected behaviour?
>>> Notably this seems to only occur only in opcodes and if arrays are
>>> involved - if I move the contents of the opcode into an instr then it
>>> works OK, and numeric/string primitives work OK in this pattern.
>>> Sresult = "anything"
>>> opcode test1, S[], 0
>>>       Sresult[] fillarray "t1", "t2"
>>>       xout Sresult
>>> endop
>>> instr 1
>>>       Sresult[] test1
>>> endin