Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
M
mjtest-tests
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Package Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • IPDSnelting
  • mjtest-tests
  • Issues
  • #6

Closed
Open
Opened Nov 13, 2018 by ufebl@ufeblContributor

Return statement only in while loop

How should we interpret If a method is declared to have a return type (§8.4.5), then a compile-time error occurs if the body of the method can complete normally (§14.1). (https://docs.oracle.com/javase/specs/jls/se11/html/jls-8.html#jls-8.4.7)?

javac rejects

public int foo() {
  if (true) {
    return 1;
  }
}

but allows

public int foo() {
  while (true) {
    return 1;
  }
}

and similar constructs where the expression of the while loop can be folded to a true boolean.

Are we allowed to reject such while constructions as well as long as there is no return after the while loop?

To upload designs, you'll need to enable LFS and have admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: IPDSnelting/mjtest-tests#6