Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7444677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:33:59+00:00 2026-05-29T11:33:59+00:00

Any one else had trouble with contracts. I have the following: public void doSomeThing(Stack

  • 0

Any one else had trouble with contracts. I have the following:

public void doSomeThing(Stack stack)
{
    Contract.Requires(stack != null);

    stack.Push("$");
    Contract.Assert(stack.Count > 0); //redundant check
    _Look(stack);
    Contract.Assert(stack.Count > 0); //this contract fails static analysis, because analyser does not know that _Look does not write to stack.
    stack.Pop();
}

private void _Look(Stack stack)
{
    //do nothing
}

The second assert is unproven, because the call to _Look may ( but does not ) change the content of the stack. Is there a way to say that _Look does not change stack? Or is there some other way to get this to work?

Note these contracts pass dynamically, it is just that the second one can not be proved statically.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:34:00+00:00Added an answer on May 29, 2026 at 11:34 am

    This answer based on idea from reading Craig Wilson’s answer.

    public void doSomeThing(Stack stack)
    {
        Contract.Requires(stack != null);
    
        stack.Push("$");
        Contract.Assert(stack.Count > 0); //redundant check
        _Look(stack);
        Contract.Assert(stack.Count > 0); //this contract fails static analysis, because analyser does not know that _Look does not write to stack.
        stack.Pop();
    }
    
    private void _Look(Stack stack)
    {
        Contract.Ensures(stack.Count == Contract.OldValue(stack.Count));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Been having lot's of trouble with this one. Let's say I had the following
HI, I was wondering if any one else had had a problem with VS2010
Has anyone else had any problems using google's Domain Tracking API, I am specifically
I'm not sure if anyone else has had trouble with this. I'm trying to
I have a public repository on github that I'm having trouble handling pull requests
Has anyone else had this issue and found a working solution? I've enabled the
Has anyone else seen people do this: private string _name; public string Name{ get{
Is anyone else having trouble running Swing applications from IntelliJ IDEA 8 Milestone 1?
has anyone else experienced this . I have SP1 but i have to kill
Has anyone else experienced this? I have uninstalled and reinstalled TortoiseSVN as well as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.