<commit_before>@import <Foundation/Foundation.j>

@implementation IvarTestClass : CPObject
{
    id ivar1 @accessors;
    var ivar2 @accessors(readonly);
    CPNumber ivar3;
}

- (void)setIvar1UsingEval:(id)value
{
    eval(@"var ivar1 = " + value);
}

- (void)doNothingToIvar1UsingEval:(id)value
{
    (function()
    {
        eval(@"var ivar1 = " + value);
    })();
}

- (void)setIvar1DespiteAWithStatement:(id)value
{
    with({})
    {
        ivar1 = value;
    }
}

- (void)doNothingToIvar1BecauseOfWithStatement:(id)value
{
    with({'ivar1':null})
    {
        ivar1 = value;
    }
}

- (void)setIvar1UsingAShadowingLocalVariable:(id)ivar1
{
    self.ivar1 = ivar1;
}

@end

@implementation IvarTest : OJTestCase
{
    IvarTestClass testClass;
}

- (void)setUp
{
    testClass = [[IvarTestClass alloc] init];
}

- (void)testDirectAccess
{
    [self assert:nil equals:testClass.ivar1];
    testClass.ivar1 = 5;
    [self assert:5 equals:testClass.ivar1];
}

- (void)testWithStatementInMethod
{
    [self assert:nil equals:testClass.ivar1];
    [testClass setIvar1DespiteAWithStatement:5];
    [self assert:5 equals:testClass.ivar1];
    [testClass doNothingToIvar1BecauseOfWithStatement:10];
    [self assert:5 equals:testClass.ivar1];
}

- (void)testEvalInMethod
{
    [self assert:nil equals:testClass.ivar1];
    [testClass setIvar1UsingEval:5];
    [self assert:5 equals:testClass.ivar1];
    [testClass doNothingToIvar1UsingEval:10];
    [self assert:5 equals:testClass.ivar1];
}

/*
TODO Reactivate this test after issue #498 is resolved.

- (void)testIvarShadowing
{
    [self assert:nil equals:testClass.ivar1];
    [testClass setIvar1UsingAShadowingLocalVariable:5];
    [self assert:5 equals:testClass.ivar1];
}*/

- (void)testAccessorGeneration
{
    [self assert:nil equals:[testClass ivar1]];
    [testClass setIvar1:10];
    [self assert:10 equals:[testClass ivar1]];
    [self assert:10 equals:testClass.ivar1];

    [self assert:nil equals:[testClass ivar2]];
    testClass.ivar2 = 5;
    [self assert:5 equals:[testClass ivar2]];
    [self assert:5 equals:testClass.ivar2];
    [self assertThrows:function()
    {
        [testClass setIvar2:6];
    }];
    [self assert:5 equals:[testClass ivar2]];

    [self assert:nil equals:testClass.ivar3];
    [self assertThrows:function()
    {
        [testClass ivar3];
    }];
    [self assertThrows:function()
    {
        [testClass setIvar3:20];
    }];
    [self assert:nil equals:testClass.ivar3];
}

@end
<commit_msg>New test cases to test ivar handling in new compiler<commit_after>@import <Foundation/Foundation.j>

@implementation IvarTestClass : CPObject
{
    id ivar1 @accessors;
    var ivar2 @accessors(readonly);
    CPNumber ivar3;
}

- (void)setIvar1UsingEval:(id)value
{
    eval(@"var ivar1 = " + value);
}

- (void)doNothingToIvar1UsingEval:(id)value
{
    (function()
    {
        eval(@"var ivar1 = " + value);
    })();
}

- (void)setIvar1DespiteAWithStatement:(id)value
{
    with({})
    {
        ivar1 = value;
    }
}

- (void)doNothingToIvar1BecauseOfWithStatement:(id)value
{
    with({'ivar1':null})
    {
        ivar1 = value;
    }
}

- (void)setIvar1UsingAShadowingLocalVariable:(id)ivar1
{
    self.ivar1 = ivar1;
}

- (void)returnShadowingLocalVariable
{
    var ivar1 = 2;

    return ivar1;
}

- (void)returnShadowingHoistedLocalVariable
{
    return ivar1;

    var ivar1;
}

- (void)returnFunctionWithShadowingFunctionParameter
{
    return function(ivar1) { return ivar1 };
}

- (void)returnFunctionWithShadowingHoistedLocalVariable
{
    return function() { return ivar1; }
    var ivar1;
}

@end

@implementation IvarTest : OJTestCase
{
    IvarTestClass testClass;
}

- (void)setUp
{
    testClass = [[IvarTestClass alloc] init];
}

- (void)testDirectAccess
{
    [self assert:nil equals:testClass.ivar1];
    testClass.ivar1 = 5;
    [self assert:5 equals:testClass.ivar1];
}

- (void)testWithStatementInMethod
{
    [self assert:nil equals:testClass.ivar1];
    [testClass setIvar1DespiteAWithStatement:5];
    [self assert:5 equals:testClass.ivar1];
    [testClass doNothingToIvar1BecauseOfWithStatement:10];
    [self assert:5 equals:testClass.ivar1];
}

- (void)testEvalInMethod
{
    [self assert:nil equals:testClass.ivar1];
    [testClass setIvar1UsingEval:5];
    [self assert:5 equals:testClass.ivar1];
    [testClass doNothingToIvar1UsingEval:10];
    [self assert:5 equals:testClass.ivar1];
}

- (void)testIvarShadowing
{
    [self assert:nil equals:testClass.ivar1];
    [testClass setIvar1UsingAShadowingLocalVariable:5];
    [self assert:5 equals:testClass.ivar1];
}

- (void)testAccessorGeneration
{
    [self assert:nil equals:[testClass ivar1]];
    [testClass setIvar1:10];
    [self assert:10 equals:[testClass ivar1]];
    [self assert:10 equals:testClass.ivar1];

    [self assert:nil equals:[testClass ivar2]];
    testClass.ivar2 = 5;
    [self assert:5 equals:[testClass ivar2]];
    [self assert:5 equals:testClass.ivar2];
    [self assertThrows:function()
    {
        [testClass setIvar2:6];
    }];
    [self assert:5 equals:[testClass ivar2]];

    [self assert:nil equals:testClass.ivar3];
    [self assertThrows:function()
    {
        [testClass ivar3];
    }];
    [self assertThrows:function()
    {
        [testClass setIvar3:20];
    }];
    [self assert:nil equals:testClass.ivar3];
}

- (void)testShadowingLocalVariable
{
    [self assert:nil equals:testClass.ivar1];
    testClass.ivar1 = 99;
    var x = [testClass returnShadowingLocalVariable];
    [self assert:2 equals:x];
}

- (void)testShadowingHoistedLocalVariable
{
    [self assert:nil equals:testClass.ivar1];
    testClass.ivar1 = 99;
    var x = [testClass returnShadowingHoistedLocalVariable];
    [self assert:"undefined" equals:typeof x];
}

- (void)testFunctionWithShadowingFunctionParameter
{
    [self assert:nil equals:testClass.ivar1];
    testClass.ivar1 = 99;
    var f = [testClass returnFunctionWithShadowingFunctionParameter];
    [self assert:8 equals:f(8)];
}

- (void)testFunctionWithShadowingHoistedLocalVariable
{
    [self assert:nil equals:testClass.ivar1];
    testClass.ivar1 = 99;
    var f = [testClass returnFunctionWithShadowingHoistedLocalVariable];

    [self assert:"undefined" equals:typeof f()];
}

@end

{'fraction_non_alphanumeric': 0.12909410448953507, 'fraction_numerical': 0.02827927783991053, 'mean_word_length': 3.9330181245074862, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5559588', 'n_tokens_mistral': 2332, 'n_tokens_neox': 2251, 'n_words': 375}