Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove csrng.net dependency #65

Merged
merged 3 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions modules/core/src/main/java/org/dhallj/core/Expr.java
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,12 @@ public static enum ImportMode {
LOCATION;

public String toString() {
switch (this) {
case RAW_TEXT:
return "Text";
case LOCATION:
return "Location";
default:
return "Code";
if (this == RAW_TEXT) {
return "Text";
} else if (this == LOCATION) {
return "Location";
} else {
return "Code";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ private static boolean isDigit(char c) {
}

private static boolean isSimpleLabel(String name) {
if (name.length() == 0) {
return false;
}

char c = name.charAt(0);
if (!isAlpha(c) && c != '_') {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,200 +15,200 @@ public Throwable fillInStackTrace() {
super(message);
}

static TypeCheckFailure makeSortError() {
static final TypeCheckFailure makeSortError() {
return new TypeCheckFailure("Sort has no type, kind, or sort");
}

static TypeCheckFailure makeUnboundVariableError(String name) {
static final TypeCheckFailure makeUnboundVariableError(String name) {
return new TypeCheckFailure("Unbound variable: " + name);
}

static TypeCheckFailure makeOperatorError(Operator operator) {
switch (operator) {
case OR:
case AND:
case EQUALS:
case NOT_EQUALS:
return new TypeCheckFailure(operator.toString() + " only works on Bools");
case PLUS:
case TIMES:
return new TypeCheckFailure(operator.toString() + " only works on Naturals");
case TEXT_APPEND:
return new TypeCheckFailure(operator.toString() + " only works on Text");
case LIST_APPEND:
return new TypeCheckFailure(operator.toString() + " only works on Lists");
case COMBINE:
case PREFER:
return new TypeCheckFailure("You can only combine records");
case COMBINE_TYPES:
return new TypeCheckFailure(
operator.toString() + " requires arguments that are record types");
case EQUIVALENT:
return new TypeCheckFailure("Incomparable expression");
default:
return new TypeCheckFailure("Operator error on " + operator.toString());
static final TypeCheckFailure makeOperatorError(Operator operator) {
String message;

if (operator == Operator.OR
|| operator == Operator.AND
|| operator == Operator.EQUALS
|| operator == Operator.NOT_EQUALS) {
message = operator.toString() + " only works on Bools";
} else if (operator == Operator.PLUS || operator == Operator.TIMES) {
message = operator.toString() + " only works on Naturals";
} else if (operator == Operator.TEXT_APPEND) {
message = operator.toString() + " only works on Text";
} else if (operator == Operator.LIST_APPEND) {
message = operator.toString() + " only works on Lists";
} else if (operator == Operator.COMBINE || operator == Operator.PREFER) {
message = "You can only combine records";
} else if (operator == Operator.COMBINE_TYPES) {
message = operator.toString() + " requires arguments that are record types";
} else if (operator == Operator.EQUIVALENT) {
message = "Incomparable expression";
} else {
message = "Operator error on " + operator.toString();
}

return new TypeCheckFailure(message);
}

static TypeCheckFailure makeListAppendError(Expr lhs, Expr rhs) {
static final TypeCheckFailure makeListAppendError(Expr lhs, Expr rhs) {
return new TypeCheckFailure("You can only append Lists with matching element types");
}

static TypeCheckFailure makeEquivalenceError(Expr lhs, Expr rhs) {
static final TypeCheckFailure makeEquivalenceError(Expr lhs, Expr rhs) {
return new TypeCheckFailure("You can only append Lists with matching element types");
}

static TypeCheckFailure makeInterpolationError(Expr interpolated, Expr interpolatedType) {
static final TypeCheckFailure makeInterpolationError(Expr interpolated, Expr interpolatedType) {
return new TypeCheckFailure("You can only interpolate Text");
}

static TypeCheckFailure makeSomeApplicationError(Expr arg, Expr argType) {
static final TypeCheckFailure makeSomeApplicationError(Expr arg, Expr argType) {
return new TypeCheckFailure("Some argument has the wrong type");
}

static TypeCheckFailure makeBuiltInApplicationError(String name, Expr arg, Expr argType) {
static final TypeCheckFailure makeBuiltInApplicationError(String name, Expr arg, Expr argType) {
return new TypeCheckFailure("Can't apply " + name);
}

static TypeCheckFailure makeApplicationTypeError(Expr expected, Expr received) {
static final TypeCheckFailure makeApplicationTypeError(Expr expected, Expr received) {
return new TypeCheckFailure("Wrong type of function argument");
}

static TypeCheckFailure makeApplicationError(Expr base, Expr arg) {
static final TypeCheckFailure makeApplicationError(Expr base, Expr arg) {
return new TypeCheckFailure("Not a function");
}

static TypeCheckFailure makeUnresolvedImportError() {
static final TypeCheckFailure makeUnresolvedImportError() {
return new TypeCheckFailure("Can't type-check unresolved import");
}

static TypeCheckFailure makeIfPredicateError(Expr type) {
static final TypeCheckFailure makeIfPredicateError(Expr type) {
return new TypeCheckFailure("Invalid predicate for if");
}

static TypeCheckFailure makeIfBranchTypeMismatchError(Expr thenType, Expr elseType) {
static final TypeCheckFailure makeIfBranchTypeMismatchError(Expr thenType, Expr elseType) {
return new TypeCheckFailure("if branches must have matching types");
}

static TypeCheckFailure makeIfBranchError(Expr type) {
static final TypeCheckFailure makeIfBranchError(Expr type) {
return new TypeCheckFailure("if branch is not a term");
}

static TypeCheckFailure makeLambdaInputError(Expr type) {
static final TypeCheckFailure makeLambdaInputError(Expr type) {
return new TypeCheckFailure("Invalid function input");
}

static TypeCheckFailure makeAssertError(Expr type) {
static final TypeCheckFailure makeAssertError(Expr type) {
return new TypeCheckFailure("Not an equivalence");
}

static TypeCheckFailure makeFieldAccessError() {
static final TypeCheckFailure makeFieldAccessError() {
return new TypeCheckFailure("Not a record or union");
}

static TypeCheckFailure makeFieldAccessRecordMissingError(String fieldName) {
static final TypeCheckFailure makeFieldAccessRecordMissingError(String fieldName) {
return new TypeCheckFailure("Missing record field: " + fieldName);
}

static TypeCheckFailure makeFieldAccessUnionMissingError(String fieldName) {
static final TypeCheckFailure makeFieldAccessUnionMissingError(String fieldName) {
return new TypeCheckFailure("Missing constructor: " + fieldName);
}

static TypeCheckFailure makeProjectionError() {
static final TypeCheckFailure makeProjectionError() {
return new TypeCheckFailure("Not a record");
}

static TypeCheckFailure makeFieldTypeError(String fieldName) {
static final TypeCheckFailure makeFieldTypeError(String fieldName) {
return new TypeCheckFailure("Invalid field type");
}

static TypeCheckFailure makeFieldDuplicateError(String fieldName) {
static final TypeCheckFailure makeFieldDuplicateError(String fieldName) {
return new TypeCheckFailure("duplicate field: " + fieldName);
}

static TypeCheckFailure makeListTypeMismatchError(Expr type1, Expr type2) {
static final TypeCheckFailure makeListTypeMismatchError(Expr type1, Expr type2) {
return new TypeCheckFailure("List elements should all have the same type");
}

static TypeCheckFailure makeListTypeError(Expr type) {
static final TypeCheckFailure makeListTypeError(Expr type) {
return new TypeCheckFailure("Invalid type for List");
}

static TypeCheckFailure makeAnnotationError(Expr expected, Expr received) {
static final TypeCheckFailure makeAnnotationError(Expr expected, Expr received) {
return new TypeCheckFailure("Expression doesn't match annotation");
}

static TypeCheckFailure makeAlternativeTypeMismatchError(Expr type) {
static final TypeCheckFailure makeAlternativeTypeMismatchError(Expr type) {
return new TypeCheckFailure("Alternative annotation mismatch");
}

static TypeCheckFailure makeAlternativeTypeError(Expr type) {
static final TypeCheckFailure makeAlternativeTypeError(Expr type) {
return new TypeCheckFailure("Invalid alternative type");
}

/** Not sure under what conditions this wouldn't be caught by the parser.s */
static TypeCheckFailure makeAlternativeDuplicateError(String fieldName) {
/** Not sure under what conditions this wouldn't be caught by the parser. */
static final TypeCheckFailure makeAlternativeDuplicateError(String fieldName) {
return new TypeCheckFailure("duplicate field: " + fieldName);
}

static TypeCheckFailure makeMergeHandlersTypeError(Expr type) {
static final TypeCheckFailure makeMergeHandlersTypeError(Expr type) {
return new TypeCheckFailure("merge expects a record of handlers");
}

static TypeCheckFailure makeMergeUnionTypeError(Expr type) {
static final TypeCheckFailure makeMergeUnionTypeError(Expr type) {
return new TypeCheckFailure("toMap expects a union or an Optional");
}

static TypeCheckFailure makeMergeHandlerMissingError(String fieldName) {
static final TypeCheckFailure makeMergeHandlerMissingError(String fieldName) {
return new TypeCheckFailure("Missing handler: " + fieldName);
}

static TypeCheckFailure makeMergeHandlerUnusedError(String fieldName) {
static final TypeCheckFailure makeMergeHandlerUnusedError(String fieldName) {
return new TypeCheckFailure("Unused handler: " + fieldName);
}

static TypeCheckFailure makeMergeHandlerTypeInvalidError(Expr expected, Expr type) {
static final TypeCheckFailure makeMergeHandlerTypeInvalidError(Expr expected, Expr type) {
return new TypeCheckFailure("Wrong handler input type");
}

static TypeCheckFailure makeMergeHandlerTypeNotFunctionError(
static final TypeCheckFailure makeMergeHandlerTypeNotFunctionError(
String fieldName, Expr expected, Expr type) {
return new TypeCheckFailure("Handler for " + fieldName + " is not a function");
}

static TypeCheckFailure makeMergeHandlerTypeMismatchError(Expr type1, Expr type2) {
static final TypeCheckFailure makeMergeHandlerTypeMismatchError(Expr type1, Expr type2) {
return new TypeCheckFailure("Handlers should have the same output type");
}

static TypeCheckFailure makeMergeHandlerTypeDisallowedError(Expr type) {
static final TypeCheckFailure makeMergeHandlerTypeDisallowedError(Expr type) {
return new TypeCheckFailure("Disallowed handler type");
}

static TypeCheckFailure makeMergeInvalidAnnotationError(Expr expected, Expr inferred) {
static final TypeCheckFailure makeMergeInvalidAnnotationError(Expr expected, Expr inferred) {
return new TypeCheckFailure("Expression doesn't match annotation");
}

static TypeCheckFailure makeToMapTypeError(Expr type) {
static final TypeCheckFailure makeToMapTypeError(Expr type) {
return new TypeCheckFailure("toMap expects a record value");
}

static TypeCheckFailure makeToMapRecordKindError(Expr type) {
static final TypeCheckFailure makeToMapRecordKindError(Expr type) {
return new TypeCheckFailure("toMap expects a record of kind Type");
}

static TypeCheckFailure makeToMapRecordTypeMismatchError(Expr type1, Expr type2) {
static final TypeCheckFailure makeToMapRecordTypeMismatchError(Expr type1, Expr type2) {
return new TypeCheckFailure("toMap expects a homogenous record");
}

static TypeCheckFailure makeToMapResultTypeMismatchError(Expr expected, Expr inferred) {
static final TypeCheckFailure makeToMapResultTypeMismatchError(Expr expected, Expr inferred) {
return new TypeCheckFailure("toMap result type doesn't match annotation");
}

static TypeCheckFailure makeToMapMissingAnnotationError() {
static final TypeCheckFailure makeToMapMissingAnnotationError() {
return new TypeCheckFailure("An empty toMap requires a type annotation");
}

static TypeCheckFailure makeToMapInvalidAnnotationError(Expr type) {
static final TypeCheckFailure makeToMapInvalidAnnotationError(Expr type) {
return new TypeCheckFailure("An empty toMap was annotated with an invalid type");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,22 @@ public enum Universe {
SORT;

public final Universe max(Universe other) {
if (this.equals(SORT) || other.equals(SORT)) {
if (this == SORT || other == SORT) {
return SORT;
} else if (this.equals(KIND) || other.equals(KIND)) {
} else if (this == KIND || other == KIND) {
return KIND;
} else {
return TYPE;
}
}

public final Expr toExpr() {
switch (this) {
case TYPE:
return Expr.Constants.TYPE;
case KIND:
return Expr.Constants.KIND;
case SORT:
return Expr.Constants.SORT;
default:
return null;
if (this == TYPE) {
return Expr.Constants.TYPE;
} else if (this == KIND) {
return Expr.Constants.KIND;
} else {
return Expr.Constants.SORT;
}
}

Expand All @@ -50,7 +47,7 @@ public static final Universe fromExpr(Expr expr) {
}

public static Universe functionCheck(Universe input, Universe output) {
if (output.equals(Universe.TYPE)) {
if (output == Universe.TYPE) {
return Universe.TYPE;
} else {
return input.max(output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class TypeCheckingUnitSuite extends ParsingTypeCheckingSuite("type-inference/suc
class TypeCheckingRegressionSuite extends TypeCheckingSuite("type-inference/success/regression")
class TypeCheckingOtherSuite extends TypeCheckingSuite("type-inference/success") {
override def slow = Set("prelude")
// Depends on http://csrng.net/, which is rate-limited (and also currently entirely down).
override def ignored = Set("CacheImports", "CacheImportsCanonicalize")
}
class TypeCheckingFailureUnitSuite extends TypeCheckingFailureSuite("type-inference/failure/unit")

Expand Down