Skip to content

Fix ASR indexing - 0 based/1 based? #11

@Smit-create

Description

@Smit-create

Let's take an example of the StringSection node. It was introduced in lpython and now it is also used in lfortran. The current StringSection in the LLVM backend is implemented based on 0-based indexing and so works for lpython but fails for lfortran. We need to have these fixes in ASR so that each front end follows the same indexing in every node.

See the following snippet in python:

def f():
    s: str = "checking"
    r: str = s[1:4]
    print(r)
f()

Works fine:

% lpython b.py
hec
% python b.py
hec

Fortran

program main
    implicit none
    character(len=10) :: b
    b = "checking"
    print *, b(1:4)
end program main

Fails:

% lfortran a.f90 
hec
% gfortran a.f90 -o a.out && ./a.out
 chec

This should also be kept the same for loops etc.

cc @certik @czgdp1807

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions