Skip to content

Compiler is too lax #19895

Open
Open

Description

@Ducasse

We can write

foo: self 

	receiver

and by default it should not be possible. If people want to do experiment then, they should change the compiler configuration.

foo: x 
	| self |
	self := 33 

Calypso let this be compiled.

Activity

  1. Ducasse commented on Jul 23, 2026

    @Ducasse
    MemberAuthor

    I would expect the following to fail.

    OpalCompiler new
    				source: 'method: self ';
    				permitFaulty: false;
    				compileOrFail.
    
  2. Ducasse commented on Jul 23, 2026

    @Ducasse
    MemberAuthor

    Looks like we can improve the semantic analyser to add notice when temps and args use reserved words.

    declareVariableNode: aVariableNode as: anOCTempVariable
    	| name var shadowing |
    	name := aVariableNode name.
    	"check if another variable with same name is visible"
    	shadowing := scope lookupVar: name.
    	var := scope addTemp: anOCTempVariable.
    	aVariableNode binding: var.
    	(shadowing isNotNil and: [ shadowing allowsShadowing not]) ifTrue: [self shadowing: shadowing withVariable: aVariableNode].
    	^ var
    
    declareTemporaryNode: aVariableNode
    	^self declareVariableNode: aVariableNode as: (TemporaryVariable named: aVariableNode name)
    
  3. Ducasse commented on Jul 23, 2026

    @Ducasse
    MemberAuthor

    same with blocks arg and temps.

    OpalCompiler new
    				source: 'method  ^ [ :self |
    					|self |
    					self := 33 ]';
    				permitFaulty: false;
    				compileOrFail.
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions