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

Fix Cycle in type declaration causes crash (#4471) #5153

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix 4471
  • Loading branch information
Siva Somayyajula committed Mar 6, 2024
commit c6260f0292b186f977a08df16abea0c9d5b4fe0c
Original file line number Diff line number Diff line change
Expand Up @@ -5066,8 +5066,7 @@ public record ResolveTypeReturn(Type ReplacementType, ExprDotName LastComponent)
if (lax) {
// we have to be careful about uses of the type being defined
var cg = enclosingTypeDefinition.EnclosingModuleDefinition.CallGraph;
var t0 = resolvedClass as ICallable;
if (t0 != null && cg.GetSCCRepresentative(t0) == cg.GetSCCRepresentative((ICallable)enclosingTypeDefinition)) {
if (resolvedClass is ICallable t0 && enclosingTypeDefinition is ICallable t1 && cg.GetSCCRepresentative(t0) == cg.GetSCCRepresentative(t1)) {
reporter.Error(MessageSource.Resolver, t.tok, "using the type being defined ('{0}') here would cause a logical inconsistency by defining a type whose cardinality exceeds itself (like the Continuum Transfunctioner, you might say its power would then be exceeded only by its mystery)", resolvedClass.Name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes me happy that this change at least slightly increases the chance of users getting to see this error message. :)

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %exits-with 0 %verify "%s"

trait YT<W> {
const f: W
}

class Y extends YT<Y -> nat> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %exits-with 2 %verify "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

trait YT<W> {
const f: W
}

class Y extends YT<Y -> nat> {
constructor(f: Y -> nat)
ensures this.f == f
{
this.f := f;
}
}

method Main()
ensures false
{
// error: knot.f calls itself without decreasing
var arrow := (x: Y) => 1 + x.f(x);
var knot := new Y(arrow);
var a := knot.f(knot);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
git-issue-4471b.dfy(12,11): Error: To prevent the creation of non-terminating functions, storing functions into an object's fields that reads the object is disallowed
1 resolution/type errors detected in git-issue-4471b.dfy
1 change: 1 addition & 0 deletions docs/dev/news/4471.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed crash caused by cycle in type declaration