dart-lang / dart-lang/language

Specification: Generic function type parameters have no scope

Open
#3,754 2 comments 0 reactions 0 assignees View on GitHub
specification
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

Cf. https://github.com/dart-lang/sdk/issues/29555. The language specification does not specify a scope for a type variable which is introduced by a generic function type (e.g., `void Function(X)`, which introduces `X` with the formal type parameter declaration list ``).

Instead, we rely on using 'capture-free substitution'. This means that the specification has no notion of the scope of such formal type parameters in a generic function type. We do get the right semantics, based on substitution, but the definition of the substitution mechanism itself could be made more explicit.

Alternatively, we could introduce language like 'a formal type parameter declaration `X extends B` enters `X` into the scope of the enclosing generic function type', etc. This would make the treatment of name binding more homogeneous, but it would probably also make the specification of everything that's concerned with generic function types substantially more verbose.

However, we do specify a scope for the formal type parameters declared by a generic function declaration (so in that sense it is similar to the treatment of classes), it's only function _types_ whose scoping differs from the rest.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.