Skip to content

How should we represent implicit downcast of a parameter default value in kernel? #31548

@stereotype441

Description

@stereotype441

The following code contains an implicit downcast of a parameter default value:

const List<Object> x = ...;
f({List<int> y: x}) {} // implicit downcast from `List<Object>` to `List<int>`.

Depending on the value of the constant x, this might or might not lead to an error. Note that due to the exisence of fromEnvironment const constructors, the front end doesn't do constant evaluation, so it can't tell whether an error should occur--detecting the error is postponed to runtime (as it is with other implicit downcasts). Currently the front end handles this by generating the following kernel representation:

static const field core::List<core::Object> x = ...;
static method f({core::List<core::int> y = self::x as{TypeError} core::List<core::int>}) → void {}

This seems undesirable, because:

  • compile-time constants are not normally allowed to contain as expressions
  • it seems a little strange that errors involving "constants" would not be detected until runtime
  • it's not clear when the runtime error is expected to occur (should it occur at the time of the call to f? At the time of execution of any method which refers to f? When the program starts?). This makes it hard to write effective tests for this scenario.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions