lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.37k stars 157 forks source link

Add support for accessing values from `Const` #2559

Closed kmr-srbh closed 4 months ago

kmr-srbh commented 4 months ago

Overview

Currently, trying to access a key from a Const dict throws a semantic error stating type mismatch. An ASR pass error is thrown when trying to access values from a Const list. This was chiefly because the case of a Const value was not addressed in handling subscript indices. The error exists for Const types in general and will be addressed in subsequent commits.

Screenshot from 2024-02-26 12-21-43

Fix

This PR checks for Const when visiting subscript indices and handles access through the contained type.

Prerequisite

This PR depends on accessing the expr_t of the contained type inside Const. I have tried high and low but could not work out a fix. The variable in question is ASR::expr_t* value which is passed to visit_SubscriptIndices.

The issue is:

We need value to get to store dict[str, i32].

kmr-srbh commented 4 months ago

The errors are okay because of the problem with value variable. See above.