Skip to content

Commit

Permalink
Add compilation error for case expected to change
Browse files Browse the repository at this point in the history
See issue chapel-lang#16508. In the future we would like 'this.type'
to convey the type information for a typeless field as in

record TypelessField {
  var field;
  proc init() { /* this.type.field indicates int in the below case */ }
}
type TypelessFieldInt = TypelessField(int);
var b: TypelessFieldInit;

---
Signed-off-by: Michael Ferguson <[email protected]>
  • Loading branch information
mppf committed Jan 26, 2021
1 parent 3c8c94a commit 8ba9f7e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
17 changes: 3 additions & 14 deletions compiler/resolution/functionResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11002,22 +11002,11 @@ static CallExpr* createGenericRecordVarDefaultInitCall(Symbol* val,
} else {
appendExpr = new SymExpr(e->value);
}
} else if (isGenericField && hasDefault == false) {
// Create a temporary to pass for the fully-generic field (e.g. "var x;")
VarSymbol* temp = newTemp("default_field_temp", e->value->typeInfo());
CallExpr* tempCall = new CallExpr(PRIM_DEFAULT_INIT_VAR, temp, e->value);

call->insertBefore(new DefExpr(temp));
call->insertBefore(tempCall);
resolveExpr(tempCall->get(2));
resolveExpr(tempCall);
appendExpr = new SymExpr(temp);

} else if (isGenericField && hasDefault == true) {
} else if (isGenericField) {
USR_FATAL_CONT(call, "this default-initialization is not yet supported");
USR_PRINT(field, "field '%s' is declared with a generic type "
"and also a default value",
USR_PRINT(field, "field '%s' is declared with a generic type",
field->name);
USR_PRINT(field, "consider separately declaraing a type field");
USR_STOP();

} else {
Expand Down
9 changes: 6 additions & 3 deletions modules/packages/Sort.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,16 @@ module Sort {
argument when no comparator is passed to a sort function
*/
const defaultComparator: DefaultComparator;
defaultComparator = new DefaultComparator();


/*
Instance of :record:`ReverseComparator`. Pass this as the ``comparator=``
argument of a sort function to reverse the sort order.
Instance of :record:`ReverseComparator` that reverses the default comparator.
Pass this as the ``comparator=``
argument of a sort function to reverse the default sort order.
*/
const reverseComparator: ReverseComparator(DefaultComparator);
const reverseComparator: ReverseComparator;
reverseComparator = new ReverseComparator();

/* Private methods */

Expand Down

0 comments on commit 8ba9f7e

Please sign in to comment.