﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
1559	Array indexing inside a function	asodja	asodja	"In the attachment are three variations of the same function (whithout change of functionality) gives three different errors.

1. When identifier 'end' is used as index (in example SimpsonTest_1.mo), the following error is printed:
{{{
[SimCodeC.tpl:4220:14-4220:14:writable] Error: Template error: Unknown expression: end
}}}

2. When first the value of {{size(vals,1)}} is assigned to a variable (in example SimpsonTest_2.mo) and then the variable is used for indexing is the error:
{{{
[SimpsonTest_2.mo:13:7-14:54:writable] Error: Illegal subscript [3:2:nvals - 1] for dimensions : in component <NO COMPONENT>
[SimpsonTest_2.mo:13:7-14:54:writable] Error: Variable vals[3:2:nvals - 1] not found in scope SimpsonTest.simpson
[SimpsonTest_2.mo:13:7-14:54:writable] Error: Illegal subscript [3:2:nvals - 1] for dimensions : in component <NO COMPONENT>
[SimpsonTest_2.mo:13:7-14:54:writable] Error: Variable vals[3:2:nvals - 1] not found in scope SimpsonTest.simpson
Error: Error occured while flattening model SimpsonTest
[SimpsonTest_2.mo:13:7-14:54:writable] Error: Illegal subscript [3:2:nvals - 1] for dimensions : in component <NO COMPONENT>
[SimpsonTest_2.mo:13:7-14:54:writable] Error: Variable vals[3:2:nvals - 1] not found in scope SimpsonTest.simpson
[SimpsonTest_2.mo:13:7-14:54:writable] Error: Illegal subscript [3:2:nvals - 1] for dimensions : in component <NO COMPONENT>
[SimpsonTest_2.mo:13:7-14:54:writable] Error: Variable vals[3:2:nvals - 1] not found in scope SimpsonTest.simpson
Error: Tried to use function .SimpsonTest.simpson, but it was not instantiated.
[SimpsonTest_2.mo:13:7-14:54:writable] Error: Illegal subscript [3:2:nvals - 1] for dimensions : in component <NO COMPONENT>
[SimpsonTest_2.mo:13:7-14:54:writable] Error: Variable vals[3:2:nvals - 1] not found in scope SimpsonTest.simpson
[SimpsonTest_2.mo:13:7-14:54:writable] Error: Illegal subscript [3:2:nvals - 1] for dimensions : in component <NO COMPONENT>
[SimpsonTest_2.mo:13:7-14:54:writable] Error: Variable vals[3:2:nvals - 1] not found in scope SimpsonTest.simpson
Error: Tried to use function .SimpsonTest.simpson, but it was not instantiated.
}}}

3. When a call to {{size(vals,1)}} is insert directly in array subscripts (example SimpsonTest_3.mo), the error is:
{{{
Error: Error building simulator. Buildlog: gcc -I""/home/anton/openmodelica/trunk/build/include/omc""  -O0 -falign-functions -march=native -mfpmath=sse  -c -o SimpsonTest_simpson.o SimpsonTest_simpson.c
SimpsonTest_simpson.c: In function ‘_SimpsonTest_simpson’:
SimpsonTest_simpson.c:23: error: ‘sum_rettype’ undeclared (first use in this function)
SimpsonTest_simpson.c:23: error: (Each undeclared identifier is reported only once
SimpsonTest_simpson.c:23: error: for each function it appears in.)
SimpsonTest_simpson.c:23: error: expected ‘;’ before ‘tmp7’
SimpsonTest_simpson.c:27: error: expected ‘;’ before ‘tmp11’
SimpsonTest_simpson.c:30: error: expected ‘;’ before ‘tmp14’
SimpsonTest_simpson.c:41: error: expected expression before ‘,’ token
SimpsonTest_simpson.c:42: error: expected expression before ‘)’ token
SimpsonTest_simpson.c:44: error: ‘tmp7’ undeclared (first use in this function)
SimpsonTest_simpson.c:45: error: expected expression before ‘,’ token
SimpsonTest_simpson.c:46: error: expected expression before ‘)’ token
SimpsonTest_simpson.c:48: error: ‘tmp11’ undeclared (first use in this function)
SimpsonTest_simpson.c:56: error: ‘tmp14’ undeclared (first use in this function)
make: *** [SimpsonTest_simpson] Error 1
}}}"	defect	closed	high		Instantiation	trunk	fixed		asodja Martin Sjölund
