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

Crash on var assignment of parameter with the same name #313

Open
potanin opened this issue Mar 21, 2019 · 2 comments
Open

Crash on var assignment of parameter with the same name #313

potanin opened this issue Mar 21, 2019 · 2 comments

Comments

@potanin
Copy link
Member

potanin commented Mar 21, 2019

The following throws a RuntimeException (possibly due to scoping of var/val's).

I attached a txt file because silly GitHub does not allow attaching source files like .wyv or wyt - is there a setting we can fix?

bug.wyv.txt

type Pair
  type T
  def first():this.T

def makeIntPair(first:Int):Pair[Int] = new
  var first:Int = first
  def first():this.T = this.first
taniwha:1 Immutability alex$ wyvern bug.wyv 
Exception in thread "main" java.lang.RuntimeException: Ambiguous findDecl: first
	at wyvern.target.corewyvernIL.type.StructuralType.findDecl(StructuralType.java:260)
	at wyvern.target.corewyvernIL.expression.FieldGet.typeCheck(FieldGet.java:67)
	at wyvern.target.corewyvernIL.decl.DefDeclaration.typeCheck(DefDeclaration.java:123)
	at wyvern.target.corewyvernIL.expression.New.typeCheck(New.java:138)
	at wyvern.target.corewyvernIL.decl.DefDeclaration.typeCheck(DefDeclaration.java:123)
	at wyvern.tools.typedAST.core.declarations.DeclSequence.genTopLevel(DeclSequence.java:194)
	at wyvern.tools.typedAST.core.Sequence.genTopLevel(Sequence.java:288)
	at wyvern.tools.typedAST.core.Script.generateTLC(Script.java:48)
	at wyvern.tools.typedAST.core.Script.generateIL(Script.java:58)
	at wyvern.target.corewyvernIL.support.ModuleResolver.loadContinuation(ModuleResolver.java:295)
	at wyvern.target.corewyvernIL.support.ModuleResolver.load(ModuleResolver.java:394)
	at wyvern.target.corewyvernIL.support.ModuleResolver.load(ModuleResolver.java:378)
	at wyvern.tools.Interpreter.main(Interpreter.java:61)
taniwha:1 Immutability alex$ wyvern bug.wyv 
Exception in thread "main" java.lang.RuntimeException: Ambiguous findDecl: first
	at wyvern.target.corewyvernIL.type.StructuralType.findDecl(StructuralType.java:260)
	at wyvern.target.corewyvernIL.expression.FieldGet.typeCheck(FieldGet.java:67)
	at wyvern.target.corewyvernIL.decl.DefDeclaration.typeCheck(DefDeclaration.java:123)
	at wyvern.target.corewyvernIL.expression.New.typeCheck(New.java:138)
	at wyvern.target.corewyvernIL.decl.DefDeclaration.typeCheck(DefDeclaration.java:123)
	at wyvern.tools.typedAST.core.declarations.DeclSequence.genTopLevel(DeclSequence.java:194)
	at wyvern.tools.typedAST.core.Sequence.genTopLevel(Sequence.java:288)
	at wyvern.tools.typedAST.core.Script.generateTLC(Script.java:48)
	at wyvern.tools.typedAST.core.Script.generateIL(Script.java:58)
	at wyvern.target.corewyvernIL.support.ModuleResolver.loadContinuation(ModuleResolver.java:295)
	at wyvern.target.corewyvernIL.support.ModuleResolver.load(ModuleResolver.java:394)
	at wyvern.target.corewyvernIL.support.ModuleResolver.load(ModuleResolver.java:378)
	at wyvern.tools.Interpreter.main(Interpreter.java:61)`
@potanin
Copy link
Member Author

potanin commented Mar 21, 2019

Actually it is worse and the following what I thought was correct code fails too:

require stdout

type Pair
  type T
  def first():this.T
  def second():this.T

def makeIntPair(f:Int, s:Int):Pair[Int] = new
  type T = Int
  var first:Int = f
  var second:Int = s
  def first():this.T = this.first
  def second():this.T = this.second
  def print():Unit
    stdout.print("First: ")
    stdout.printInt(this.first)
    stdout.println()
    stdout.print("Second: ")
    stdout.printInt(this.second)
    stdout.println()

var pair1:Pair[Int] = makeIntPair(3, 2)
var pair2:Pair[Int] = makeIntPair(4, 5)

pair1.print()
pair2.print()
taniwha:1 Immutability alex$ wyvern hello.wyv 
Exception in thread "main" java.lang.RuntimeException: Ambiguous findDecl: first
	at wyvern.target.corewyvernIL.type.StructuralType.findDecl(StructuralType.java:260)
	at wyvern.target.corewyvernIL.expression.FieldGet.typeCheck(FieldGet.java:67)
	at wyvern.target.corewyvernIL.expression.MethodCall.lambda$getArgTypes$0(MethodCall.java:208)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
	at java.base/java.util.LinkedList$LLSpliterator.forEachRemaining(LinkedList.java:1239)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
	at wyvern.target.corewyvernIL.expression.MethodCall.getArgTypes(MethodCall.java:209)
	at wyvern.target.corewyvernIL.expression.MethodCall.typeMethodDeclaration(MethodCall.java:463)
	at wyvern.target.corewyvernIL.expression.MethodCall.typeCheck(MethodCall.java:145)
	at wyvern.tools.typedAST.interfaces.ExpressionAST.genTopLevel(ExpressionAST.java:29)
	at wyvern.tools.typedAST.core.Sequence.genTopLevel(Sequence.java:274)
	at wyvern.tools.typedAST.core.Sequence.generateIL(Sequence.java:222)
	at wyvern.tools.typedAST.core.declarations.DefDeclaration.generateDecl(DefDeclaration.java:194)
	at wyvern.tools.typedAST.core.expressions.New.generateIL(New.java:135)
	at wyvern.tools.typedAST.core.expressions.New.generateIL(New.java:26)
	at wyvern.tools.typedAST.core.declarations.DefDeclaration.generateDecl(DefDeclaration.java:194)
	at wyvern.tools.typedAST.core.declarations.DefDeclaration.topLevelGen(DefDeclaration.java:200)
	at wyvern.tools.typedAST.core.declarations.DeclSequence.updateTLC(DeclSequence.java:220)
	at wyvern.tools.typedAST.core.declarations.DeclSequence.genTopLevel(DeclSequence.java:190)
	at wyvern.tools.typedAST.core.Sequence.genTopLevel(Sequence.java:274)
	at wyvern.tools.typedAST.core.Script.generateTLC(Script.java:48)
	at wyvern.tools.typedAST.core.Script.generateIL(Script.java:58)
	at wyvern.target.corewyvernIL.support.ModuleResolver.loadContinuation(ModuleResolver.java:295)
	at wyvern.target.corewyvernIL.support.ModuleResolver.load(ModuleResolver.java:394)
	at wyvern.target.corewyvernIL.support.ModuleResolver.load(ModuleResolver.java:378)
	at wyvern.tools.Interpreter.main(Interpreter.java:61)

@JonathanAldrich
Copy link
Member

JonathanAldrich commented Mar 21, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants