chapel-lang / chapel-lang/chapel
Using 'domain' in certain contexts is a syntax error
- Dominant language
- Chapel
- Stars
- 2k
- Forks
- 449
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 119
Description
I have found the following situations where the 'domain' keyword/typename is not allowed, where I think maybe it should be. All of the following situations result in syntax errors. This can be worked around in all cases by replacing `domain` with `domain(?)`.
#### Using a domain in a where clause as a bare typename
```chapel
proc foo(x) where x.type == domain { } // syntax error near '{'
proc bar(x)
where isSubtype(x.type, domain) // syntax error near ')'
{ }
```
#### Using a domain in a type expression as a bare typename
```chapel
type t = domain; // syntax error near ';'
```
```chapel
proc foo(type t) do writeln(t:string);
foo(domain); // syntax error near ')'
```
```chapel
record R {
type T;
proc init(type T) do this.T = T;
}
var x: R(domain); // syntax error near ';'
var y = new R(domain); // syntax error near ';'
type z = R(domain); // syntax error near ';'
```
Note that resolving the syntax error for this case by writing `domain` as `domain(?)` ends up being a resolution error anyways, but this issue is not about that, just the syntax issues.
#### Using a domain in a cast
```chapel
operator :(x:range, type t: domain) do return {x};
var d = (1..10): domain; // syntax error near ';'
```
---
Compare this with some other typenames. Replacing `domain` in any of these codes with, for example, `range`, `locale`, or `imag` compiles and works as expected.
```chapel
type x = range; // valid code
var x = new R(locale); // valid code
foo(imag); // valid code
```
It is potentially up for debate if we allow this, especially as we move to a world where `domain(?)` is the preferred way to write a generic domain. So the right thing to do here may be to just make this a better syntax error. But I think the inconsistencies with other keywords/typenames is weird and potentially confusing.
Contributor guide
Research direction
Start by reproducing the issue's where-clause, type-expression, constructor, and cast snippets in Chapel, then compare them with the corresponding range, locale, and imag examples. Determine whether bare domain should be accepted consistently or receive a clearer syntax diagnostic; done means the chosen behavior is implemented and covered for the reported contexts.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100